问题:
我有一个ConversionService
需要创建 s 集合的 bean ( ) Converter
。因此,在我的@Configuration
班级中,我有一个@Bean
带有Collection<Converter>
特定@Qualifier
.
对于 my ,我使用 my像这样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);
}
}