|
@@ -1,5 +1,6 @@
|
|
|
package com.jkcredit.query.record.config;
|
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.http.HttpHost;
|
|
|
import org.apache.http.auth.AuthScope;
|
|
|
import org.apache.http.auth.UsernamePasswordCredentials;
|
|
@@ -13,30 +14,39 @@ import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.util.Properties;
|
|
|
+
|
|
|
/**
|
|
|
* @author xusonglin
|
|
|
* @version V1.0
|
|
|
**/
|
|
|
@Configuration
|
|
|
+@Slf4j
|
|
|
public class EsConfig {
|
|
|
@Value("${ElasticSearch.host}")
|
|
|
private String host;
|
|
|
@Value("${ElasticSearch.port}")
|
|
|
private Integer port;
|
|
|
- @Value("${ElasticSearch.username}")
|
|
|
- private String username;
|
|
|
- @Value("${ElasticSearch.password}")
|
|
|
- private String password;
|
|
|
-
|
|
|
- public static final RequestOptions COMMON_OPTIONS;
|
|
|
-
|
|
|
- static {
|
|
|
- RequestOptions.Builder builder = RequestOptions.DEFAULT.toBuilder();
|
|
|
- COMMON_OPTIONS = builder.build();
|
|
|
- }
|
|
|
+ @Value("${ElasticSearch.userFilePath}")
|
|
|
+ private String userFilePath;
|
|
|
|
|
|
@Bean
|
|
|
public RestHighLevelClient esRestClient() {
|
|
|
+ Properties properties = new Properties();
|
|
|
+ InputStream in;
|
|
|
+ try {
|
|
|
+ in = new FileInputStream(new File(userFilePath));
|
|
|
+ properties.load(in);
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error("读取Es配置文件失败:", e);
|
|
|
+ }
|
|
|
+ String username = properties.getProperty("username");
|
|
|
+ String password = properties.getProperty("password");
|
|
|
+
|
|
|
RestClientBuilder builder = null;
|
|
|
// 可以指定多个es
|
|
|
builder = RestClient.builder(
|