问题:
我有一个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);
}
}