0
我试图用弹簧和嵌入式弹性建立休息API。尝试启动我的应用程序时遇到NoSuchBeanDefinitionException。带弹簧的自动装配嵌入式弹性
目前,我有这样的布线弹性DB:
@Configuration
public class EsConfig {
Node node;
@Bean
public Client es() {
node = nodeBuilder().local(true).node();
return node.client();
}
(Destructor)
}
,并在控制器:
@RestController
public class Controller {
@Autowired
public Client elasticSearchClient;
...
}
但是当我启动它,我得到这个异常:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'controller': Injection of autowired dependencies failed;
nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: public org.elasticsearch.client.Client package.Controller.elasticSearchClient;
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException:
No qualifying bean of type [org.elasticsearch.client.Client] found for dependency:
expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
我已经尝试了几个不同的注释,但我很明显地离开了。
缺少哪个bean?你能否在你的问题中包括例外情况?不确定什么是空的'@ Qualifier',但如果不指定限定符,则不需要它。 – zapl
它缺少Controller类中的客户端Bean。我更新了这个问题,以包括例外情况。我之前在限定词中有一个名字,只是忘记完全删除它。就像我说的,我一直在尝试很多不同的东西。 –
啊,试着让你的配置成为'@ Configuration',这是一个提供'@ Bean'的类,'@ Component'本身就只是一个'@ Bean'。如果你不使用命名bean的方法,请去除限定符:) – zapl