作者 王勇

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

... ... @@ -102,6 +102,11 @@ management:
shutdown:
enabled: true
es:
hostname: 192.168.37.139
port: 9200
scheme: http
# 基础信息配置
info:
version: 1.0
... ...
... ... @@ -3,6 +3,7 @@ package com.sunyo.wlpt.message.bus.service.config;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.config.AbstractElasticsearchConfiguration;
... ... @@ -16,23 +17,24 @@ import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
@Configuration
public class ElasticSearchConfig extends AbstractElasticsearchConfiguration {
@Value("${es.hostname}")
private String hostname;
@Value("${es.port}")
private Integer port;
@Value("${es.scheme}")
private String scheme;
@Override
@Bean
public RestHighLevelClient elasticsearchClient()
{
RestHighLevelClient client = new RestHighLevelClient(
RestClient.builder(
// 天生契合集群,有几个es环境,就 new HttpHost 几个,用,相隔
new HttpHost("192.168.37.139", 9200, "http")
new HttpHost(hostname, port, scheme)
)
);
return client;
... ...
... ... @@ -19,7 +19,8 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket createRestApi() {
public Docket createRestApi()
{
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
... ... @@ -27,15 +28,14 @@ public class SwaggerConfig {
.paths(PathSelectors.any())
.build();
}
/**
* 默认访问地址是:http://${host}:${port}/doc.html
*/
private ApiInfo apiInfo() {
private ApiInfo apiInfo()
{
return new ApiInfoBuilder()
.title("消息平台控制中心 APIs")
.description("swagger-bootstrap-ui")
.title("消息总线平台--后台管理服务")
.description("消息总线平台--后台管理服务")
.termsOfServiceUrl("http://localhost:9030/")
.contact("523186180@qq.com")
.contact("子诚")
.version("1.0.0")
.build();
}
... ...