No qualifying bean of type ‘org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate‘ a

这篇具有很好参考价值的文章主要介绍了No qualifying bean of type ‘org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate‘ a。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

报错

No qualifying bean of type ‘org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate’ available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

提示找不到 ElasticsearchRestTemplate

解决方法

写一个配置类注入文章来源地址https://www.toymoban.com/news/detail-580299.html

package com.xjhqre.search.config;

import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.config.AbstractElasticsearchConfiguration;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;

@Configuration
public class RestClientConfig extends AbstractElasticsearchConfiguration {
    @Override
    @Bean
    public RestHighLevelClient elasticsearchClient() {
        HttpHost host = new HttpHost("es的ip地址", 9200, HttpHost.DEFAULT_SCHEME_NAME);
        RestClientBuilder builder = RestClient.builder(host);

        // 若elasticsearch有密码则配置
        CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("账号", "密码"));
        builder.setHttpClientConfigCallback(f -> f.setDefaultCredentialsProvider(credentialsProvider));

        return new RestHighLevelClient(builder);
    }

     @Bean
     public ElasticsearchRestTemplate elasticsearchRestTemplate() {
     return new ElasticsearchRestTemplate(this.elasticsearchClient());
     }
}

到了这里,关于No qualifying bean of type ‘org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate‘ a的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 【Spring常见错误】No qualifying bean of type

    org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name \\\'com.ssmpdemo.ServiceTest\\\': Unsatisfied dependency expressed through field \\\'userService\\\'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type \\\'com.ssmpdemo.service.UserService\\\' available: expected at leas

    2023年04月08日
    浏览(30)
  • Java No qualifying bean of type * available:expected at least * bean which qualifies as autowire问题解决

    org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type \\\'com.xudongbase.user.dubbo.service.userDubboService\\\' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {} 1、使用@AllArgsContructor注解进行自动装配时,默认是以@Autowired注解装配的,但是其中有一

    2024年02月07日
    浏览(27)
  • 【错误】A component required a bean of type ‘org.springframework.security.config.annotation.ObjectPostPr

    Description: A component required a bean of type \\\'org.springframework.security.config.annotation.ObjectPostProcessor\\\' that could not be found. Action: Consider defining a bean of type \\\'org.springframework.security.config.annotation.ObjectPostProcessor\\\' in your configuration.   描述: 组件需要“org.springframework.security.configannotation”类型的

    2024年02月13日
    浏览(27)
  • mybatis添加分页配置时报错 No bean named ‘org.springframework...ConfigurationClassPostProcessor.importRegistry

    场景:在mybatis 添加分页配置时报错 现象:No bean named ‘org.springframework.context.annotation.ConfigurationClassPostProcessor.importRegistry 原因:版本问题 正确版本: com.baomidou mybatis-plus-boot-starter 3.4.0 错误版本: com.baomidou mybatis-plus-boot-starter 3.5.3.1 附MybatisPlusConfig 配置文件: package com.examp

    2024年02月13日
    浏览(22)
  • Could not autowire. No beans of ‘DiscoveryClient‘ type found.

    一、导错了包 DiscoveryClient对应有两个包: org.springframework.cloud.client.discovery.DiscoveryClient; com.netflix.discovery.DiscoveryClient; 目前导入的包是: 改成第一个包,发现不再报红了。

    2024年02月11日
    浏览(34)
  • 针对mq错误org.springframework.messaging.MessagingException: No route info of this topic........

    org.springframework.messaging.MessagingException: No route info of this topic, course-sms-topic See http://rocketmq.apache.org/docs/faq/ for further details.; nested exception is org.apache.rocketmq.client.exception.MQClientException: No route info of this topic, course-sms-topic See http://rocketmq.apache.org/docs/faq/ for further details.     at org.apa

    2023年04月08日
    浏览(47)
  • @Autowired报错Could not autowire. No beans of ‘XXX‘ type found

      IDEA中使用 @Autowired 报错 Could not autowire. No beans of \\\'XXX\\\' type found ,错误大致意思为:没有匹配到类型为XXX的bean。   个人觉得,注入 controller 的 service 虽然一般来说我们都是注入一个接口,但是该接口有实现类,并且使用 @Service 进行关联,所以注入类型应该也可以视为一

    2024年02月07日
    浏览(35)
  • idea报错:Could not autowire. No beans of ‘UserService‘ type found.

    点个关注,必回关 翻译:无法自动连线。未找到“用户服务”类型的服务类。 当报错之后idea会提示错误,不过程序的编译和运行都是没有问题的(这个错误提示不会产生任何印象) 解决方案 解决方案1: Settings - Editor - Inspections - Spring - Spring Core - Code - Autowiring for Bean Class

    2024年02月11日
    浏览(35)
  • idea报“Could not autowire. No beans of ‘UserMapper‘ type found. ”错解决办法

    idea具有检测功能,接口不能直接创建bean的,需要用动态代理技术来解决。 1.修改idea的配置 1.点击file,选择setting 2.搜索inspections,找到Spring 3.找到Spring子目录下的Springcore 4.在Springcore的子目录下找到code 5.把seyerity选项改成警告 2.修改代码 1,@Autowrited改为@Autowrited(required = false)

    2024年02月05日
    浏览(51)
  • IDEA提示找不到Mapper接口:Could not autowire.No beans of ‘xxxMapper‘ type found

    我们可以看到,上面的红色警告在提示我们,找不到 xxxMaper 这个类型的 bean。 为啥呢? 因为 @Mapper 这个注解是 Mybatis 提供的,而 @Autowried 注解是 Spring 提供的,IDEA能理解 Spring 的上下文,但是却和 Mybatis 关联不上。而且我们可以根据 @Autowried 源码看到,默认情况下,@Autowri

    2024年02月08日
    浏览(33)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包