ES报错The following candidates were found but could not be injected

avatar
作者
筋斗云
阅读量:0

遇到的问题

The following candidates were found but could not be injected:
- Bean method ‘elasticsearchTemplate’ in ‘ElasticsearchDataConfiguration.RestClientConfiguration’ not loaded because @ConditionalOnMissingBean (names: elasticsearchTemplate types: org.springframework.data.elasticsearch.core.ElasticsearchOperations; SearchStrategy: all) found beans of type ‘org.springframework.data.elasticsearch.core.ElasticsearchOperations’ elasticsearchTemplate and found beans named elasticsearchTemplate

Error starting ApplicationContext. To display the conditions report re-run your application with ‘debug’ enabled.
2024-02-19 20:11:04.894 ERROR 31172 — [ main] o.s.b.d.LoggingFailureAnalysisReporter :


APPLICATION FAILED TO START


Description:

Field elasticsearchRestTemplate in cn.yiyuan.gift.service.impl.GiftSearchServiceImpl required a bean of type ‘org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate’ that could not be found.

The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)

The following candidates were found but could not be injected:
- Bean method ‘elasticsearchTemplate’ in ‘ElasticsearchDataConfiguration.RestClientConfiguration’ not loaded because @ConditionalOnMissingBean (names: elasticsearchTemplate types: org.springframework.data.elasticsearch.core.ElasticsearchOperations; SearchStrategy: all) found beans of type ‘org.springframework.data.elasticsearch.core.ElasticsearchOperations’ elasticsearchTemplate and found beans named elasticsearchTemplate

Action:
Consider revisiting the entries above or defining a bean of type ‘org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate’ in your configuration.
Process finished with exit code 1
解决
注入的es不匹配
@Autowired
private ElasticsearchRestTemplate elasticsearchRestTemplate;
修改为正确的
@Autowired
private ElasticsearchTemplate elasticsearchRestTemplate;
问题完美解决,希望可以帮到你

广告一刻

为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!