首页 > 编程语言 > 详细

SpringBoot 集成 ES

时间:2020-09-11 16:26:39      阅读:56      评论:0      收藏:0      [点我收藏+]

第一步创建一个SpringBoot项目

技术分享图片

 

 技术分享图片

 

 点击Next

技术分享图片

 

 修改为自己想要的名字之后点击下一步

技术分享图片

 

 选择自己需要的依赖关系,点击Next

技术分享图片

 

 配置好路径后点击 Finish

等待项目构建完成后,记得看一下,ES 的版本

技术分享图片

 

 如果是低版本的springBoot 可能ES的版本比较低

建议修改为和自己使用的ES的版本一致

技术分享图片

 

修改后点击Maven的刷新

 技术分享图片

 

 刷新后发现,版本已经修改完毕

技术分享图片

 

 编写配置类

package com.dance.danceesapi.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * ElasticSearch配置类
 * @author ZYGisComputer
 */
@Configuration
public class ElasticSearchClientConfig {

    @Bean
    public RestHighLevelClient restHighLevelClient(){
        return new RestHighLevelClient(
                RestClient.builder(
                        new HttpHost("127.0.0.1",9200,"http")
                )
        );
    }

}

在用的时候注入就可以了

package com.flower.floweres;

import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class FlowerEsApplication {
    
    @Autowired
    @Qualifier("restHighLevelClient")
    public RestHighLevelClient restHighLevelClient;

    public static void main(String[] args) {
        SpringApplication.run(FlowerEsApplication.class, args);
    }

}

到此集成完毕

作者:彼岸舞

时间:2020\09\11

内容关于:ElasticSearch

本文来源于网络,只做技术分享,一概不负任何责任

 

SpringBoot 集成 ES

原文:https://www.cnblogs.com/flower-dance/p/13651577.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!