与Spring Boot中用于动态注入的javax.enterprise.inject.Instance等效
我正在将代码从JEE迁移到SpringBoot。我在JEE中使用了cool dynamic injection和javax.enterprise.injecte.Instance类: 只是说明一下:与Spring Boot中用于动态注入的javax.enterprise.inject.Instance等效,java,spring-boot,dependency-injection,cdi,Java,Spring Boot,Dependency Injection,Cdi,我正在将代码从JEE迁移到SpringBoot。我在JEE中使用了cool dynamic injection和javax.enterprise.injecte.Instance类: 只是说明一下: @Inject private Instance<CCIntentHandler> allMycandidates; @Inject 私人实例所有我的候选人; 将使用继承我的类路径中CCIntentHandler接口的所有类填充所有my候选类,然后我可以简单地使用以下内容进行迭代:
@Inject
private Instance<CCIntentHandler> allMycandidates;
@Inject
私人实例所有我的候选人;
将使用继承我的类路径中CCIntentHandler接口的所有类填充所有my候选类,然后我可以简单地使用以下内容进行迭代:
Iterator<CCIntentHandler> iterator = allMycandidates.iterator()
Iterator Iterator=allMycandidates.Iterator()
再也不需要了。如何在Spring Boot中实现这一点
谢谢如果您
@Autowire
a列表
,Spring将注入Foo
的所有实例
所以,弹簧相当于
@Inject
private Instance<CCIntentHandler> allMycandidates;
@Inject
私人实例所有我的候选人;
。。。是:
@Autowire
private List<CCIntentHandler> allMycandidates;
@Autowire
私人名单所有我的候选人;
更新1回应此评论:
CCIntentHandler接口或实现此接口的类是否需要任何Spring注释
Spring必须知道任何cContentHandler
的实例,这可以通过以下方式实现:
- 用
注释实现@Component
的每个类,并确保这些类由Spring Boot扫描CCIntentHandler
- 提供一个公共方法来返回实现
的每个类,并用CCIntentHandler
注释这些公共方法,确保包含这些公共方法的类用@Bean
注释,并且Spring Boot扫描该配置类@Configuration
更多关于bean声明和依赖注入的详细信息。谢谢!CCIntentHandler接口或实现此接口的类是否需要任何Spring注释?@icordoba我已经更新了答案,以解决您最后的评论