您现在的位置是:首页 > 文章详情

SpringCloud系列----->SpringBoot项目中整合ElasticSearch

日期:2019-08-03点击:711
SpringBoot项目中整合ElasticSearch: 1、首先在maven的pom.xml中加入以下配置: <properties> <!-- 设定和你的es版本相同的版本号,springboot默认的是2.x的版本--> <elasticsearch.version>6.5.4</elasticsearch.version> </properties> 2、在pom.xml中增加: <dependency> <groupId>org.elasticsearch.client</groupId> <artifactId>transport</artifactId> <version>${elasticsearch.version}</version> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j.core</artifactId> <version>2.7</version> </dependency> 3、在application.properties文件中添加 appender.console.type = Console appender.console.name = console appender.console.layout.type = PatternLayout appender.console.layout.pattern = [%t] %-5p %c - %m%n rootLogger.level = info rootLogger.appenderRef.console.ref = console 4、在项目中新建config目录,添加EsConfig.class文件: @Configuration public class EsConfig { @Bean public TransportClient client() throws UnknownHostException { InetSocketTransportAddress node = new InetSocketTransportAddress( InetAddress.getByName("localhost"), 9300 ); Settings settings = Settings.builder().put("cluster.name","biges").build(); TransportClient client = new PreBuiltTransportClient(settings); client.addTransportAddress(node); return client; } } 
原文链接:https://yq.aliyun.com/articles/712540
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章