将组件扫描的类转换为工厂包装的bean

时间:2019-07-05 10:56:03

标签: java spring spring-framework-beans

通过FactoryBean实现,您可以在代码中的其他位置注册初始化回调:

@Bean fun documentSettings(): CustomizingFactoryBean<DocumentSettings> = 
                                               CustomizingFactoryBean.create()

@Bean fun documentSettingsCustomizerA(): Customizer<DocumentSettings> = Customizer { 
   settings -> settings.someVal = 1
}

@Bean fun documentSettingsCustomizerB(): Customizer<DocumentSettings> = Customizer { 
   settings -> settings.otherVal = 2
}

这将创建同时运行两个DocumentSettings的{​​{1}}实例。

我想要实现的是跳过注册Customizer并依靠组件扫描:

CustomizingFactoryBean<DocumentSettings>

是否为此创建自定义BeanFactoryPostProcessor?

我是否可以插入现有的一种处理方式@CustomizableComponent class DocumentSettings( var someVal: Int, var otherVal: Int) @Service@Component

0 个答案:

没有答案