自动装配已过滤的列表

时间:2016-01-22 15:25:45

标签: java spring spring-boot autowired spring-java-config

我有一个接口(Component)的多个实现(ComponentA,ComponentB,ComponentC),需要根据属性文件提供的属性自动连接到配置类(MyConfiguration)。

MyConfiguration类;

@Configuration
@PropertySource("classpath:settings.properties")
public class MyConfiguration implements ConfigurationService {

@Value("#{'${enabled.components}'.split(',')}")
private Set<String> enabledComponentQualifiers;

@Autowired
private Set<Component> enabledComponentSet;
...

ComponentA类(ComponentB,ComponentC具有相同的结构);

@Component("componenta")
public class ComponentA implements Component {
...

settings.property文件;

enabled.components=componenta,componentb

我希望自动设置的set(上面的enabledComponentSet)只包含在enabled.components属性中过滤的组件。

使用JavaConfig的最佳方法是什么?

0 个答案:

没有答案
相关问题