0
造成的问题之后:需要创建的Converter
个集合bean定义从@Configuration
我有一颗豆(ConversionService
)。因此,在我的@Configuration
类中,我有一个@Bean
,这是一个Collection<Converter>
,具体的@Qualifier
。
对于我ConversionService
@Bean
,我使用收到Converter
集合作为参数我@Qualifier
这样的:
@Bean
public ConversionService createConversionService(@Qualifier("converters") converters) {
// here I perform the ConversionService creation
}
这工作是到底我想要的。但我有几个@Configuration
类,每个类都应该能够添加一些东西到Converter
集合。我最初虽然也许有一种方法来实现从@Configuration
类读取bean定义后调用的方法。事情是这样的:
@Configuration
public class MyConfiguration {
@Autowired
@Qualifier("converters")
private Collection<Converter> converters;
public void init() {
converters.add(xy);
}
}
甚至
@Configuration
public class MyConfiguration {
public void init(@Qualifier("converters") Collection<Converter> converters) {
converters.add(xy);
}
}
有没有办法只使用spring类来做到这一点? @PostConstruct是一个javax注释。 –
完美,我得到它实现org.springframework.beans.factory.InitializingBean感谢您的帮助亚历克斯! –
@JavaMentor:你可以发布你的答案吗? –