Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/375.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
与Spring Boot中用于动态注入的javax.enterprise.inject.Instance等效_Java_Spring Boot_Dependency Injection_Cdi - Fatal编程技术网

与Spring Boot中用于动态注入的javax.enterprise.inject.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候选类,然后我可以简单地使用以下内容进行迭代:

我正在将代码从JEE迁移到SpringBoot。我在JEE中使用了cool dynamic injection和javax.enterprise.injecte.Instance类:

只是说明一下:

@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
    注释实现
    CCIntentHandler
    的每个类,并确保这些类由Spring Boot扫描

  • 提供一个公共方法来返回实现
    CCIntentHandler
    的每个类,并用
    @Bean
    注释这些公共方法,确保包含这些公共方法的类用
    @Configuration
    注释,并且Spring Boot扫描该配置类

更多关于bean声明和依赖注入的详细信息。

谢谢!CCIntentHandler接口或实现此接口的类是否需要任何Spring注释?@icordoba我已经更新了答案,以解决您最后的评论