Jelajahi Sumber

增加外置配置

XuShengTao 6 tahun lalu
induk
melakukan
550abeb437

+ 10 - 2
src/main/java/com/es/demo/TransportClientConfig.java

@@ -5,6 +5,7 @@ import org.elasticsearch.client.transport.TransportClient;
 import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.common.transport.TransportAddress;
 import org.elasticsearch.transport.client.PreBuiltTransportClient;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.core.convert.support.DefaultConversionService;
@@ -26,12 +27,19 @@ import java.net.UnknownHostException;
  **/
 @Configuration
 public class TransportClientConfig extends ElasticsearchConfigurationSupport {
+    @Value("${bok.es.cluster.name}")
+    protected String name;
+    @Value("${bok.es.port}")
+    protected String port;
+    @Value("${bok.es.address}")
+    protected String address;
     @Bean
     public Client elasticsearchClient() throws UnknownHostException {
-        Settings settings = Settings.builder().put("cluster.name", "se4-es").build();
+        System.out.println(name+" "+address+" "+port);
+        Settings settings = Settings.builder().put("cluster.name", name).build();
         TransportClient client = new PreBuiltTransportClient(settings);
         //client.addTransportAddress(new TransportAddress(InetAddress.getByName("192.168.68.76"), 9300));
-        client.addTransportAddress(new TransportAddress(InetAddress.getByName("127.0.0.1"), 19300));
+        client.addTransportAddress(new TransportAddress(InetAddress.getByName(address), Integer.valueOf(port)));
         return client;
     }
 

+ 4 - 1
src/main/resources/application.properties

@@ -10,4 +10,7 @@ spring.freemarker.suffix=.ftl
 spring.data.rest.basePath=/api
 spring.data.rest.returnBodyOnUpdate=true
 spring.data.rest.returnBodyOnCreate=true
-spring.data.web.pageable.one-indexed-parameters=true
+spring.data.web.pageable.one-indexed-parameters=true
+bok.es.cluster.name=se4-es
+bok.es.port=9300
+bok.es.address=192.168.68.76