正在显示
2 个修改的文件
包含
10 行增加
和
3 行删除
@@ -3,6 +3,7 @@ package com.sunyo.wlpt.message.bus.service.config; | @@ -3,6 +3,7 @@ package com.sunyo.wlpt.message.bus.service.config; | ||
3 | import org.apache.http.HttpHost; | 3 | import org.apache.http.HttpHost; |
4 | import org.elasticsearch.client.RestClient; | 4 | import org.elasticsearch.client.RestClient; |
5 | import org.elasticsearch.client.RestHighLevelClient; | 5 | import org.elasticsearch.client.RestHighLevelClient; |
6 | +import org.springframework.beans.factory.annotation.Value; | ||
6 | import org.springframework.context.annotation.Bean; | 7 | import org.springframework.context.annotation.Bean; |
7 | import org.springframework.context.annotation.Configuration; | 8 | import org.springframework.context.annotation.Configuration; |
8 | import org.springframework.data.elasticsearch.config.AbstractElasticsearchConfiguration; | 9 | import org.springframework.data.elasticsearch.config.AbstractElasticsearchConfiguration; |
@@ -16,23 +17,24 @@ import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate; | @@ -16,23 +17,24 @@ import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate; | ||
16 | @Configuration | 17 | @Configuration |
17 | public class ElasticSearchConfig extends AbstractElasticsearchConfiguration { | 18 | public class ElasticSearchConfig extends AbstractElasticsearchConfiguration { |
18 | 19 | ||
19 | - | 20 | + @Value("${es.hostname}") |
20 | private String hostname; | 21 | private String hostname; |
21 | 22 | ||
23 | + @Value("${es.port}") | ||
22 | private Integer port; | 24 | private Integer port; |
23 | 25 | ||
26 | + @Value("${es.scheme}") | ||
24 | private String scheme; | 27 | private String scheme; |
25 | 28 | ||
26 | 29 | ||
27 | @Override | 30 | @Override |
28 | @Bean | 31 | @Bean |
29 | - | ||
30 | public RestHighLevelClient elasticsearchClient() | 32 | public RestHighLevelClient elasticsearchClient() |
31 | { | 33 | { |
32 | RestHighLevelClient client = new RestHighLevelClient( | 34 | RestHighLevelClient client = new RestHighLevelClient( |
33 | RestClient.builder( | 35 | RestClient.builder( |
34 | // 天生契合集群,有几个es环境,就 new HttpHost 几个,用,相隔 | 36 | // 天生契合集群,有几个es环境,就 new HttpHost 几个,用,相隔 |
35 | - new HttpHost("192.168.37.139", 9200, "http") | 37 | + new HttpHost(hostname, port, scheme) |
36 | ) | 38 | ) |
37 | ); | 39 | ); |
38 | return client; | 40 | return client; |
-
请 注册 或 登录 后发表评论