@Component
public class AbServiceImpl implements AAService{
@Override
public void aa() {
...
}
}
@Component
public class AcServiceImpl implements AAService{
@Override
public void aa() {
...
}
}
通过构造器注入收集Aa 接口对应的实现类
@Component
public class AAServiceApplicationContext {
private final List<AAService> AAServices;
public BuildServiceApplicationContext(List<AAService> AAServices) {
this.AAServices= AAServices;
}
public List<AAService> getAAServices() {
return AAServices;
}
}
获取实现类集合
@Autowired
AAServiceApplicationContext aAServiceApplicationContext;
@Test
public void test1(){
List<AAService> list = aAServiceApplicationContext.getAAServices();
if(!CollectionUtils.isEmpty(buildService)){
for (AAService aAService: list ) {
aAService.aa();
}
}
}