【RestTemplate/Elasticsearch】如何让RestTemplate访问限制以用户名密码的Elasticsearch节点
【程序】
import org.apache.catalina.authenticator.BasicAuthenticator; import org.apache.http.auth.AuthScope; import org.apache.http.auth.UsernamePasswordCredentials; import org.apache.http.client.HttpClient; import org.apache.http.impl.client.BasicCredentialsProvider; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.springframework.http.client.ClientHttpRequestFactory; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.web.client.RestTemplate; public class AccessCredentialEs { public static void main(String[] args){ BasicCredentialsProvider provider=new BasicCredentialsProvider(); provider.setCredentials(AuthScope.ANY,new UsernamePasswordCredentials("elastic","123456")); CloseableHttpClient httpClient= HttpClients.custom().setDefaultCredentialsProvider(provider).useSystemProperties().build(); ClientHttpRequestFactory factory=new HttpComponentsClientHttpRequestFactory(httpClient); RestTemplate tplt=new RestTemplate(); tplt.setRequestFactory(factory); String rsps=tplt.getForObject("http://192.168.32.128:9200",String.class); System.out.println(rsps); } }
【输出】
C:\Java8\bin\java.exe "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2021.3.2\lib\idea_rt.jar=56011:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2021.3.2\bin" -Dfile.encoding=UTF-8 -classpath C:\java8\jre\lib\charsets.jar;C:\java8\jre\lib\deploy.jar;C:\java8\jre\lib\ext\access-bridge-64.jar;C:\java8\jre\lib\ext\cldrdata.jar;C:\java8\jre\lib\ext\dnsns.jar;C:\java8\jre\lib\ext\jaccess.jar;C:\java8\jre\lib\ext\jfxrt.jar;C:\java8\jre\lib\ext\localedata.jar;C:\java8\jre\lib\ext\nashorn.jar;C:\java8\jre\lib\ext\sunec.jar;C:\java8\jre\lib\ext\sunjce_provider.jar;C:\java8\jre\lib\ext\sunmscapi.jar;C:\java8\jre\lib\ext\sunpkcs11.jar;C:\java8\jre\lib\ext\zipfs.jar;C:\java8\jre\lib\javaws.jar;C:\java8\jre\lib\jce.jar;C:\java8\jre\lib\jfr.jar;C:\java8\jre\lib\jfxswt.jar;C:\java8\jre\lib\jsse.jar;C:\java8\jre\lib\management-agent.jar;C:\java8\jre\lib\plugin.jar;C:\java8\jre\lib\resources.jar;C:\java8\jre\lib\rt.jar;C:\Users\ufo\IdeaProjects\RestAccessEs\target\classes;C:\Users\ufo\IdeaProjects\RestAccessEs\jar\ojdbc6.jar;C:\Users\ufo\IdeaProjects\RestAccessEs\jar\orai18n.jar;C:\Users\ufo\.m2\repository\org\springframework\boot\spring-boot-starter-web\2.1.3.RELEASE\spring-boot-starter-web-2.1.3.RELEASE.jar;C:\Users\ufo\.m2\repository\org\springframework\boot\spring-boot-starter\2.1.3.RELEASE\spring-boot-starter-2.1.3.RELEASE.jar;C:\Users\ufo\.m2\repository\org\springframework\boot\spring-boot\2.1.3.RELEASE\spring-boot-2.1.3.RELEASE.jar;C:\Users\ufo\.m2\repository\org\springframework\boot\spring-boot-autoconfigure\2.1.3.RELEASE\spring-boot-autoconfigure-2.1.3.RELEASE.jar;C:\Users\ufo\.m2\repository\org\springframework\boot\spring-boot-starter-logging\2.1.3.RELEASE\spring-boot-starter-logging-2.1.3.RELEASE.jar;C:\Users\ufo\.m2\repository\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;C:\Users\ufo\.m2\repository\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;C:\Users\ufo\.m2\repository\org\slf4j\slf4j-api\1.7.25\slf4j-api-1.7.25.jar;C:\Users\ufo\.m2\repository\org\apache\logging\log4j\log4j-to-slf4j\2.11.2\log4j-to-slf4j-2.11.2.jar;C:\Users\ufo\.m2\repository\org\apache\logging\log4j\log4j-api\2.11.2\log4j-api-2.11.2.jar;C:\Users\ufo\.m2\repository\org\slf4j\jul-to-slf4j\1.7.25\jul-to-slf4j-1.7.25.jar;C:\Users\ufo\.m2\repository\javax\annotation\javax.annotation-api\1.3.2\javax.annotation-api-1.3.2.jar;C:\Users\ufo\.m2\repository\org\springframework\spring-core\5.1.5.RELEASE\spring-core-5.1.5.RELEASE.jar;C:\Users\ufo\.m2\repository\org\springframework\spring-jcl\5.1.5.RELEASE\spring-jcl-5.1.5.RELEASE.jar;C:\Users\ufo\.m2\repository\org\yaml\snakeyaml\1.23\snakeyaml-1.23.jar;C:\Users\ufo\.m2\repository\org\springframework\boot\spring-boot-starter-json\2.1.3.RELEASE\spring-boot-starter-json-2.1.3.RELEASE.jar;C:\Users\ufo\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.9.8\jackson-datatype-jdk8-2.9.8.jar;C:\Users\ufo\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.9.8\jackson-datatype-jsr310-2.9.8.jar;C:\Users\ufo\.m2\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.9.8\jackson-module-parameter-names-2.9.8.jar;C:\Users\ufo\.m2\repository\org\springframework\boot\spring-boot-starter-tomcat\2.1.3.RELEASE\spring-boot-starter-tomcat-2.1.3.RELEASE.jar;C:\Users\ufo\.m2\repository\org\apache\tomcat\embed\tomcat-embed-core\9.0.16\tomcat-embed-core-9.0.16.jar;C:\Users\ufo\.m2\repository\org\apache\tomcat\embed\tomcat-embed-el\9.0.16\tomcat-embed-el-9.0.16.jar;C:\Users\ufo\.m2\repository\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.16\tomcat-embed-websocket-9.0.16.jar;C:\Users\ufo\.m2\repository\org\hibernate\validator\hibernate-validator\6.0.14.Final\hibernate-validator-6.0.14.Final.jar;C:\Users\ufo\.m2\repository\javax\validation\validation-api\2.0.1.Final\validation-api-2.0.1.Final.jar;C:\Users\ufo\.m2\repository\org\jboss\logging\jboss-logging\3.3.2.Final\jboss-logging-3.3.2.Final.jar;C:\Users\ufo\.m2\repository\com\fasterxml\classmate\1.3.4\classmate-1.3.4.jar;C:\Users\ufo\.m2\repository\org\springframework\spring-web\5.1.5.RELEASE\spring-web-5.1.5.RELEASE.jar;C:\Users\ufo\.m2\repository\org\springframework\spring-beans\5.1.5.RELEASE\spring-beans-5.1.5.RELEASE.jar;C:\Users\ufo\.m2\repository\org\springframework\spring-webmvc\5.1.5.RELEASE\spring-webmvc-5.1.5.RELEASE.jar;C:\Users\ufo\.m2\repository\org\springframework\spring-aop\5.1.5.RELEASE\spring-aop-5.1.5.RELEASE.jar;C:\Users\ufo\.m2\repository\org\springframework\spring-context\5.1.5.RELEASE\spring-context-5.1.5.RELEASE.jar;C:\Users\ufo\.m2\repository\org\springframework\spring-expression\5.1.5.RELEASE\spring-expression-5.1.5.RELEASE.jar;C:\Users\ufo\.m2\repository\com\alibaba\fastjson\1.2.48\fastjson-1.2.48.jar;C:\Users\ufo\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.9.8\jackson-databind-2.9.8.jar;C:\Users\ufo\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.9.0\jackson-annotations-2.9.0.jar;C:\Users\ufo\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.9.8\jackson-core-2.9.8.jar;C:\Users\ufo\.m2\repository\org\mybatis\mybatis\3.5.9\mybatis-3.5.9.jar;C:\Users\ufo\.m2\repository\org\apache\httpcomponents\httpclient\4.5.13\httpclient-4.5.13.jar;C:\Users\ufo\.m2\repository\org\apache\httpcomponents\httpcore\4.4.13\httpcore-4.4.13.jar;C:\Users\ufo\.m2\repository\commons-logging\commons-logging\1.2\commons-logging-1.2.jar;C:\Users\ufo\.m2\repository\commons-codec\commons-codec\1.11\commons-codec-1.11.jar AccessCredentialEs 14:47:57.586 [main] DEBUG org.springframework.web.client.RestTemplate - HTTP GET http://192.168.32.128:9200 14:47:57.601 [main] DEBUG org.springframework.web.client.RestTemplate - Accept=[text/plain, application/json, application/*+json, */*] 14:47:57.609 [main] DEBUG org.apache.http.client.protocol.RequestAddCookies - CookieSpec selected: default 14:47:57.617 [main] DEBUG org.apache.http.client.protocol.RequestAuthCache - Auth cache not set in the context 14:47:57.617 [main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection request: [route: {}->http://192.168.32.128:9200][total available: 0; route allocated: 0 of 5; total allocated: 0 of 10] 14:47:57.625 [main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection leased: [id: 0][route: {}->http://192.168.32.128:9200][total available: 0; route allocated: 1 of 5; total allocated: 1 of 10] 14:47:57.629 [main] DEBUG org.apache.http.impl.execchain.MainClientExec - Opening connection {}->http://192.168.32.128:9200 14:47:57.629 [main] DEBUG org.apache.http.impl.conn.DefaultHttpClientConnectionOperator - Connecting to /192.168.32.128:9200 14:47:57.629 [main] DEBUG org.apache.http.impl.conn.DefaultHttpClientConnectionOperator - Connection established 192.168.32.1:56016<->192.168.32.128:9200 14:47:57.633 [main] DEBUG org.apache.http.impl.execchain.MainClientExec - Executing request GET / HTTP/1.1 14:47:57.633 [main] DEBUG org.apache.http.impl.execchain.MainClientExec - Target auth state: UNCHALLENGED 14:47:57.633 [main] DEBUG org.apache.http.impl.execchain.MainClientExec - Proxy auth state: UNCHALLENGED 14:47:57.633 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> GET / HTTP/1.1 14:47:57.633 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Accept: text/plain, application/json, application/*+json, */* 14:47:57.633 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Host: 192.168.32.128:9200 14:47:57.633 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Connection: Keep-Alive 14:47:57.633 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> User-Agent: Apache-HttpClient/4.5.13 (Java/1.8.0_212) 14:47:57.633 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Accept-Encoding: gzip,deflate 14:47:57.633 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "GET / HTTP/1.1[\r][\n]" 14:47:57.633 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Accept: text/plain, application/json, application/*+json, */*[\r][\n]" 14:47:57.633 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Host: 192.168.32.128:9200[\r][\n]" 14:47:57.633 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Connection: Keep-Alive[\r][\n]" 14:47:57.633 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "User-Agent: Apache-HttpClient/4.5.13 (Java/1.8.0_212)[\r][\n]" 14:47:57.633 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Accept-Encoding: gzip,deflate[\r][\n]" 14:47:57.633 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "[\r][\n]" 14:47:57.636 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "HTTP/1.1 401 Unauthorized[\r][\n]" 14:47:57.636 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "WWW-Authenticate: Basic realm="security" charset="UTF-8"[\r][\n]" 14:47:57.636 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "content-type: application/json; charset=UTF-8[\r][\n]" 14:47:57.636 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "content-encoding: gzip[\r][\n]" 14:47:57.636 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "content-length: 192[\r][\n]" 14:47:57.636 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "[\r][\n]" 14:47:57.636 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "[0x1f][0x8b][0x8][0x0][0x0][0x0][0x0][0x0][0x0][0x0][0xd4]NI[\n]" 14:47:57.636 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "[0xc2]@[0x10][0xfc][0xca][0xd0][0xe7][0x4][0x15]<H[0xc0][0x83][0x82]>[0xc0][0x85][0x1c][0x92] [0xcd][0xd8][0x9a][0x81]$[0xa3][0xdd]=`[0x8][0xf9][0xbb][0x13][0xf][0xfa][0x6]oUEm[0x3][0x10][0xb3]g[0xc8][0x6]`[0xef][0xf5]b1[0x8]AV[0xc][0xa0][0xfd]#[0x2][0x10][0xb2][0x81][0x9d][0xf6][0x17]zYz[0xa8][0xf3][0x1d]$[0xc0][0x84][0x12]A[0x6][0xad][0x13]q[0xdd][0xdd]`[0xd0][0x9a]:u[0x16]'[0x87][0xb1]L[0xd7][0x89]b#[0xe6][0xe6][0xd9][0x1c]v[0xc7][0x93]az[0x6][0x12]5[0xc5][0xac][0x8a][0x15]5[0xe1][0x95]>[0xbb]y[0x9e][0xa7][0x9b]_~[0x1a][0xdd][0xa2]8[0x1b][0x3][0xd8][0xb4][0xeb][0xf2]{[0xa1][0x4]ckd![0x8d][0xe2][0xf9][0xb4]OW%[0xc0]8V[0xc9][0xff]|M@[0x14]5[0x8]d[0xcb][0xf9]b|[0x3][0x0][0x0][0xff][0xff][0x3][0x0][0xcf][0x8d][0xa6][0x9e]}[0x1][0x0][0x0]" 14:47:57.640 [main] DEBUG org.apache.http.headers - http-outgoing-0 << HTTP/1.1 401 Unauthorized 14:47:57.640 [main] DEBUG org.apache.http.headers - http-outgoing-0 << WWW-Authenticate: Basic realm="security" charset="UTF-8" 14:47:57.640 [main] DEBUG org.apache.http.headers - http-outgoing-0 << content-type: application/json; charset=UTF-8 14:47:57.640 [main] DEBUG org.apache.http.headers - http-outgoing-0 << content-encoding: gzip 14:47:57.640 [main] DEBUG org.apache.http.headers - http-outgoing-0 << content-length: 192 14:47:57.644 [main] DEBUG org.apache.http.impl.execchain.MainClientExec - Connection can be kept alive indefinitely 14:47:57.644 [main] DEBUG org.apache.http.impl.auth.HttpAuthenticator - Authentication required 14:47:57.644 [main] DEBUG org.apache.http.impl.auth.HttpAuthenticator - 192.168.32.128:9200 requested authentication 14:47:57.644 [main] DEBUG org.apache.http.impl.client.TargetAuthenticationStrategy - Authentication schemes in the order of preference: [Negotiate, Kerberos, NTLM, CredSSP, Digest, Basic] 14:47:57.644 [main] DEBUG org.apache.http.impl.client.TargetAuthenticationStrategy - Challenge for Negotiate authentication scheme not available 14:47:57.644 [main] DEBUG org.apache.http.impl.client.TargetAuthenticationStrategy - Challenge for Kerberos authentication scheme not available 14:47:57.644 [main] DEBUG org.apache.http.impl.client.TargetAuthenticationStrategy - Challenge for NTLM authentication scheme not available 14:47:57.644 [main] DEBUG org.apache.http.impl.client.TargetAuthenticationStrategy - Challenge for CredSSP authentication scheme not available 14:47:57.644 [main] DEBUG org.apache.http.impl.client.TargetAuthenticationStrategy - Challenge for Digest authentication scheme not available 14:47:57.644 [main] DEBUG org.apache.http.impl.auth.HttpAuthenticator - Selected authentication options: [BASIC [complete=true]] 14:47:57.648 [main] DEBUG org.apache.http.impl.execchain.MainClientExec - Executing request GET / HTTP/1.1 14:47:57.648 [main] DEBUG org.apache.http.impl.execchain.MainClientExec - Target auth state: CHALLENGED 14:47:57.648 [main] DEBUG org.apache.http.impl.auth.HttpAuthenticator - Generating response to an authentication challenge using basic scheme 14:47:57.652 [main] DEBUG org.apache.http.impl.execchain.MainClientExec - Proxy auth state: UNCHALLENGED 14:47:57.652 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> GET / HTTP/1.1 14:47:57.652 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Accept: text/plain, application/json, application/*+json, */* 14:47:57.652 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Host: 192.168.32.128:9200 14:47:57.652 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Connection: Keep-Alive 14:47:57.652 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> User-Agent: Apache-HttpClient/4.5.13 (Java/1.8.0_212) 14:47:57.652 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Accept-Encoding: gzip,deflate 14:47:57.652 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Authorization: Basic ZWxhc3RpYzoxMjM0NTY= 14:47:57.652 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "GET / HTTP/1.1[\r][\n]" 14:47:57.652 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Accept: text/plain, application/json, application/*+json, */*[\r][\n]" 14:47:57.652 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Host: 192.168.32.128:9200[\r][\n]" 14:47:57.652 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Connection: Keep-Alive[\r][\n]" 14:47:57.652 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "User-Agent: Apache-HttpClient/4.5.13 (Java/1.8.0_212)[\r][\n]" 14:47:57.652 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Accept-Encoding: gzip,deflate[\r][\n]" 14:47:57.652 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Authorization: Basic ZWxhc3RpYzoxMjM0NTY=[\r][\n]" 14:47:57.652 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "[\r][\n]" 14:47:57.722 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "HTTP/1.1 200 OK[\r][\n]" 14:47:57.722 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "content-type: application/json; charset=UTF-8[\r][\n]" 14:47:57.722 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "content-encoding: gzip[\r][\n]" 14:47:57.722 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "content-length: 322[\r][\n]" 14:47:57.722 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "[\r][\n]" 14:47:57.722 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "[0x1f][0x8b][0x8][0x0][0x0][0x0][0x0][0x0][0x0][0x0]|[0x91][0xbb]n[0xc3] [0x14][0x86][0xf7]<[0x85][0xe5]9F`;%[0xce][0xd6][0xaa][*eH[0x97]v[0xb1][0x8e][0xb9][0xc4]H[0x18][0x12].I[0xa3]([0xef]^_[0xda][0xaa]V[0xa5]n[0xc0]w>[0xce][0xf9][0xe1][0xb6]H[0x92][0xd4]@'[0xd2]d[0xd3]/,[0x17][0x19]I[0x97][0xc3]![0xd3][0xd1][0x7][0xe1][0xea][0x1f][0xa8][0x15][0x98][0x83]o[0xc1][0xcc]y[0x8c][0x8a][0x8f]r[0xfb][0xf0][0xe8][0xd9][0xb]<[0xed][0xf1][0xe9][0xba][0xdb]ry"[0xcf][0xbb][0xf5]e*>[0xb][0xe7][0x95]5C[0xdd][0xad][0xdf][0xf]=c[0xd7][0x8]7[0x8a][0x14][0x11][0x82][0xa6][0xae]=h[0xa2][0xd2][0xbc][0x96][0x1a][0xce]v[0xc2]\H[0x88]:[0xcc]y[0xb8][0x1e][0xa7][0x91][0x3][0xb8]9i[0xc1][0xb7]#[0x91][0x92]P[0xbc][0xa2][0x84][0x94],'U[0xc5]*F[0x9a]F0Fs[0x8a]q[0x1][0x15][0xa6][0xc][0xf3][0x86][0xc2]\[0xe7][0x10][0xa6][0x8b]s[0x9c][0x93][0xc][0xe7][0x19]Y[0xbd][0x92]bS[0x96][0x1b]\[0xa1][0xa2]*q[0x91][0xbf][0xcf][\r]o[0xe0][0xe8][[0x1b][0x6]K[0x82][0xf6][0xe2]+[0x88][0x8e]L[0x18]Q[0xff][0x8a][0x9e][0xae][0x11]E[0xf8][0xdb][0xee][0x94]Q][0xec][0xea][0x8b]r[0xa2]f[0xb6];BP[0x8d][0xd2]*\g[0xce][0x3]Z[0xff]u[0x94][0xe1][0xe2][0xe3]_[0x9]#[0x9c]5"[0x0]I[0xfb]g[0xbd][0x8f][0x9f][0x10][0xe0][0xa0][0x95][0x99][0xd2][0xbd][0xd9][0x98]l[0x8d][0xbd],[0x13]i][0xb2][0x17][0xe0]X[0x9b].[0xee][0x8b]O[0x0][0x0][0x0][0xff][0xff][0x3][0x0][0x82]F[0xd1][0xf4][0x10][0x2][0x0][0x0]" 14:47:57.722 [main] DEBUG org.apache.http.headers - http-outgoing-0 << HTTP/1.1 200 OK 14:47:57.722 [main] DEBUG org.apache.http.headers - http-outgoing-0 << content-type: application/json; charset=UTF-8 14:47:57.722 [main] DEBUG org.apache.http.headers - http-outgoing-0 << content-encoding: gzip 14:47:57.722 [main] DEBUG org.apache.http.headers - http-outgoing-0 << content-length: 322 14:47:57.722 [main] DEBUG org.apache.http.impl.execchain.MainClientExec - Connection can be kept alive indefinitely 14:47:57.722 [main] DEBUG org.apache.http.impl.auth.HttpAuthenticator - Authentication succeeded 14:47:57.722 [main] DEBUG org.apache.http.impl.client.TargetAuthenticationStrategy - Caching 'basic' auth scheme for http://192.168.32.128:9200 14:47:57.734 [main] DEBUG org.springframework.web.client.RestTemplate - Response 200 OK 14:47:57.738 [main] DEBUG org.springframework.web.client.RestTemplate - Reading to [java.lang.String] as "application/json;charset=UTF-8" 14:47:57.738 [main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection [id: 0][route: {}->http://192.168.32.128:9200] can be kept alive indefinitely 14:47:57.738 [main] DEBUG org.apache.http.impl.conn.DefaultManagedHttpClientConnection - http-outgoing-0: set socket timeout to 0 14:47:57.738 [main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection released: [id: 0][route: {}->http://192.168.32.128:9200][total available: 1; route allocated: 1 of 5; total allocated: 1 of 10] { "name" : "node-1", "cluster_name" : "liangshan", "cluster_uuid" : "h6AscLaBS0qyOKdfq1DO8w", "version" : { "number" : "7.11.1", "build_flavor" : "default", "build_type" : "tar", "build_hash" : "ff17057114c2199c9c1bbecc727003a907c0db7a", "build_date" : "2021-02-15T13:44:09.394032Z", "build_snapshot" : false, "lucene_version" : "8.7.0", "minimum_wire_compatibility_version" : "6.8.0", "minimum_index_compatibility_version" : "6.0.0-beta1" }, "tagline" : "You Know, for Search" } Process finished with exit code 0
【依赖】
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>2.1.3.RELEASE</version> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.5.13</version> </dependency>
END