作者 王勇

将es环境放到application.yml文件中

@@ -102,6 +102,11 @@ management: @@ -102,6 +102,11 @@ management:
102 shutdown: 102 shutdown:
103 enabled: true 103 enabled: true
104 104
  105 +es:
  106 + hostname: 192.168.37.139
  107 + port: 9200
  108 + scheme: http
  109 +
105 # 基础信息配置 110 # 基础信息配置
106 info: 111 info:
107 version: 1.0 112 version: 1.0
@@ -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;
@@ -19,7 +19,8 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2; @@ -19,7 +19,8 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
19 @EnableSwagger2 19 @EnableSwagger2
20 public class SwaggerConfig { 20 public class SwaggerConfig {
21 @Bean 21 @Bean
22 - public Docket createRestApi() { 22 + public Docket createRestApi()
  23 + {
23 return new Docket(DocumentationType.SWAGGER_2) 24 return new Docket(DocumentationType.SWAGGER_2)
24 .apiInfo(apiInfo()) 25 .apiInfo(apiInfo())
25 .select() 26 .select()
@@ -27,15 +28,14 @@ public class SwaggerConfig { @@ -27,15 +28,14 @@ public class SwaggerConfig {
27 .paths(PathSelectors.any()) 28 .paths(PathSelectors.any())
28 .build(); 29 .build();
29 } 30 }
30 - /**  
31 - * 默认访问地址是:http://${host}:${port}/doc.html  
32 - */  
33 - private ApiInfo apiInfo() { 31 +
  32 + private ApiInfo apiInfo()
  33 + {
34 return new ApiInfoBuilder() 34 return new ApiInfoBuilder()
35 - .title("消息平台控制中心 APIs")  
36 - .description("swagger-bootstrap-ui") 35 + .title("消息总线平台--后台管理服务")
  36 + .description("消息总线平台--后台管理服务")
37 .termsOfServiceUrl("http://localhost:9030/") 37 .termsOfServiceUrl("http://localhost:9030/")
38 - .contact("523186180@qq.com") 38 + .contact("子诚")
39 .version("1.0.0") 39 .version("1.0.0")
40 .build(); 40 .build();
41 } 41 }