从 Maven 项目连接到弹性搜索的问题
Issue connecting to elastic search from a maven project
在我的 maven-Spring 项目中,我正在尝试连接到 ElasticSearch:
TransportClient esclient = TransportClient.builder().build()
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
我添加了 maven 依赖 - org.elasticsearch 2.4.5
我不断收到:
Servlet.service() 用于 servlet 调度程序抛出异常
java.lang.NoSuchMethodError: com.google.common.util.concurrent.MoreExecutors.directExecutor()Ljava/util/concurrent/Executor;
在 org.elasticsearch.threadpool.ThreadPool.(ThreadPool.java:192)
在 org.elasticsearch.client.transport.TransportClient$Builder.build(TransportClient.java:133)
在 com.controller.AppController.loginPage(AppController.java:204)
在 sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)
在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
在 java.lang.reflect.Method.invoke(Method.java:498)
在 org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
要摆脱这个异常:
我尝试添加番石榴 18.0 依赖项,在 org.elasticSearch 中添加排除项,并为 Maven 着色番石榴。
不添加番石榴依赖或排除,这是我的dependency:tree
--- maven-dependency-plugin:2.6:tree (default-cli) ---
com.spring.mvc:App:war:1.0-SNAPSHOT
+- javax:javaee-web-api:jar:7.0:provided
+- org.springframework:spring-core:jar:4.2.5.RELEASE:compile
| \- commons-logging:commons-logging:jar:1.2:compile
+- org.springframework:spring-web:jar:4.2.5.RELEASE:compile
| +- org.springframework:spring-aop:jar:4.2.5.RELEASE:compile
| +- org.springframework:spring-beans:jar:4.2.5.RELEASE:compile
| \- org.springframework:spring-context:jar:4.2.5.RELEASE:compile
+- org.springframework:spring-webmvc:jar:4.2.5.RELEASE:compile
| \- org.springframework:spring-expression:jar:4.2.5.RELEASE:compile
+- org.springframework:spring-tx:jar:4.2.5.RELEASE:compile
+- org.springframework:spring-orm:jar:4.2.5.RELEASE:compile
| \- org.springframework:spring-jdbc:jar:4.2.5.RELEASE:compile
+- org.springframework.security:spring-security-web:jar:4.0.4.RELEASE:compile
| +- aopalliance:aopalliance:jar:1.0:compile
| \- org.springframework.security:spring-security-core:jar:4.0.4.RELEASE:compile
+- org.springframework.security:spring-security-config:jar:4.0.4.RELEASE:compile
+- org.springframework.security:spring-security-taglibs:jar:4.0.4.RELEASE:compile
| \- org.springframework.security:spring-security-acl:jar:4.0.4.RELEASE:compile
+- org.hibernate:hibernate-core:jar:4.3.11.Final:compile
| +- org.jboss.logging:jboss-logging:jar:3.1.3.GA:compile
| +- org.jboss.logging:jboss-logging-annotations:jar:1.2.0.Beta1:compile
| +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:jar:1.0.0.Final:compile
| +- dom4j:dom4j:jar:1.6.1:compile
| | \- xml-apis:xml-apis:jar:1.0.b2:compile
| +- org.hibernate.common:hibernate-commons-annotations:jar:4.0.5.Final:compile
| +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
| +- org.javassist:javassist:jar:3.18.1-GA:compile
| +- antlr:antlr:jar:2.7.7:compile
| \- org.jboss:jandex:jar:1.1.0.Final:compile
+- javax.validation:validation-api:jar:1.1.0.Final:compile
+- org.hibernate:hibernate-validator:jar:5.1.3.Final:compile
| \- com.fasterxml:classmate:jar:1.0.0:compile
+- mysql:mysql-connector-java:jar:5.1.31:compile
+- ch.qos.logback:logback-classic:jar:1.1.7:compile
| +- ch.qos.logback:logback-core:jar:1.1.7:compile
| \- org.slf4j:slf4j-api:jar:1.7.20:compile
+- javax.servlet:javax.servlet-api:jar:3.1.0:compile
+- javax.servlet.jsp:javax.servlet.jsp-api:jar:2.3.1:compile
+- javax.servlet:jstl:jar:1.2:compile
\- org.elasticsearch:elasticsearch:jar:2.4.5:compile
+- org.apache.lucene:lucene-core:jar:5.5.4:compile
+- org.apache.lucene:lucene-backward-codecs:jar:5.5.4:compile
+- org.apache.lucene:lucene-analyzers-common:jar:5.5.4:compile
+- org.apache.lucene:lucene-queries:jar:5.5.4:compile
+- org.apache.lucene:lucene-memory:jar:5.5.4:compile
+- org.apache.lucene:lucene-highlighter:jar:5.5.4:compile
+- org.apache.lucene:lucene-queryparser:jar:5.5.4:compile
| \- org.apache.lucene:lucene-sandbox:jar:5.5.4:compile
+- org.apache.lucene:lucene-suggest:jar:5.5.4:compile
| \- org.apache.lucene:lucene-misc:jar:5.5.4:compile
+- org.apache.lucene:lucene-join:jar:5.5.4:compile
| \- org.apache.lucene:lucene-grouping:jar:5.5.4:compile
+- org.apache.lucene:lucene-spatial:jar:5.5.4:compile
| +- org.apache.lucene:lucene-spatial3d:jar:5.5.4:compile
| \- com.spatial4j:spatial4j:jar:0.5:compile
+- com.google.guava:guava:jar:18.0:compile
+- org.elasticsearch:securesm:jar:1.0:compile
+- com.carrotsearch:hppc:jar:0.7.1:compile
+- joda-time:joda-time:jar:2.9.5:compile
+- com.fasterxml.jackson.core:jackson-core:jar:2.8.1:compile
+- com.fasterxml.jackson.dataformat:jackson-dataformat-smile:jar:2.8.1:compile
+- com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:jar:2.8.1:compile
+- com.fasterxml.jackson.dataformat:jackson-dataformat-cbor:jar:2.8.1:compile
+- org.yaml:snakeyaml:jar:1.15:compile
+- io.netty:netty:jar:3.10.6.Final:compile
+- com.ning:compress-lzf:jar:1.0.2:compile
+- com.tdunning:t-digest:jar:3.0:compile
+- org.hdrhistogram:HdrHistogram:jar:2.1.6:compile
+- commons-cli:commons-cli:jar:1.3.1:compile
\- com.twitter:jsr166e:jar:1.1.0:compile
仔细查看后,我发现 GlassFish 自身的依赖项泄漏到应用程序类路径中(并且 GF 使用较旧的 Guava)因此 Glassfish4.1 用户的修复将更新 /glassfish/modules 中的 guava.jar番石榴 19 版本。
使用此依赖项:
<dependency>
<groupId>org.glassfish.jersey.bundles.repackaged</groupId>
<artifactId>jersey-guava</artifactId>
<version>2.19</version>
</dependency>
由于解决这个问题需要干预 GF 自己的库并且容易出错,我搬到了 Tomcat 并且没有其他更改它工作正常。
在我的 maven-Spring 项目中,我正在尝试连接到 ElasticSearch: TransportClient esclient = TransportClient.builder().build() .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
我添加了 maven 依赖 - org.elasticsearch 2.4.5
我不断收到: Servlet.service() 用于 servlet 调度程序抛出异常 java.lang.NoSuchMethodError: com.google.common.util.concurrent.MoreExecutors.directExecutor()Ljava/util/concurrent/Executor; 在 org.elasticsearch.threadpool.ThreadPool.(ThreadPool.java:192) 在 org.elasticsearch.client.transport.TransportClient$Builder.build(TransportClient.java:133) 在 com.controller.AppController.loginPage(AppController.java:204) 在 sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法) 在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在 java.lang.reflect.Method.invoke(Method.java:498) 在 org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
要摆脱这个异常: 我尝试添加番石榴 18.0 依赖项,在 org.elasticSearch 中添加排除项,并为 Maven 着色番石榴。
不添加番石榴依赖或排除,这是我的dependency:tree
--- maven-dependency-plugin:2.6:tree (default-cli) ---
com.spring.mvc:App:war:1.0-SNAPSHOT
+- javax:javaee-web-api:jar:7.0:provided
+- org.springframework:spring-core:jar:4.2.5.RELEASE:compile
| \- commons-logging:commons-logging:jar:1.2:compile
+- org.springframework:spring-web:jar:4.2.5.RELEASE:compile
| +- org.springframework:spring-aop:jar:4.2.5.RELEASE:compile
| +- org.springframework:spring-beans:jar:4.2.5.RELEASE:compile
| \- org.springframework:spring-context:jar:4.2.5.RELEASE:compile
+- org.springframework:spring-webmvc:jar:4.2.5.RELEASE:compile
| \- org.springframework:spring-expression:jar:4.2.5.RELEASE:compile
+- org.springframework:spring-tx:jar:4.2.5.RELEASE:compile
+- org.springframework:spring-orm:jar:4.2.5.RELEASE:compile
| \- org.springframework:spring-jdbc:jar:4.2.5.RELEASE:compile
+- org.springframework.security:spring-security-web:jar:4.0.4.RELEASE:compile
| +- aopalliance:aopalliance:jar:1.0:compile
| \- org.springframework.security:spring-security-core:jar:4.0.4.RELEASE:compile
+- org.springframework.security:spring-security-config:jar:4.0.4.RELEASE:compile
+- org.springframework.security:spring-security-taglibs:jar:4.0.4.RELEASE:compile
| \- org.springframework.security:spring-security-acl:jar:4.0.4.RELEASE:compile
+- org.hibernate:hibernate-core:jar:4.3.11.Final:compile
| +- org.jboss.logging:jboss-logging:jar:3.1.3.GA:compile
| +- org.jboss.logging:jboss-logging-annotations:jar:1.2.0.Beta1:compile
| +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:jar:1.0.0.Final:compile
| +- dom4j:dom4j:jar:1.6.1:compile
| | \- xml-apis:xml-apis:jar:1.0.b2:compile
| +- org.hibernate.common:hibernate-commons-annotations:jar:4.0.5.Final:compile
| +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
| +- org.javassist:javassist:jar:3.18.1-GA:compile
| +- antlr:antlr:jar:2.7.7:compile
| \- org.jboss:jandex:jar:1.1.0.Final:compile
+- javax.validation:validation-api:jar:1.1.0.Final:compile
+- org.hibernate:hibernate-validator:jar:5.1.3.Final:compile
| \- com.fasterxml:classmate:jar:1.0.0:compile
+- mysql:mysql-connector-java:jar:5.1.31:compile
+- ch.qos.logback:logback-classic:jar:1.1.7:compile
| +- ch.qos.logback:logback-core:jar:1.1.7:compile
| \- org.slf4j:slf4j-api:jar:1.7.20:compile
+- javax.servlet:javax.servlet-api:jar:3.1.0:compile
+- javax.servlet.jsp:javax.servlet.jsp-api:jar:2.3.1:compile
+- javax.servlet:jstl:jar:1.2:compile
\- org.elasticsearch:elasticsearch:jar:2.4.5:compile
+- org.apache.lucene:lucene-core:jar:5.5.4:compile
+- org.apache.lucene:lucene-backward-codecs:jar:5.5.4:compile
+- org.apache.lucene:lucene-analyzers-common:jar:5.5.4:compile
+- org.apache.lucene:lucene-queries:jar:5.5.4:compile
+- org.apache.lucene:lucene-memory:jar:5.5.4:compile
+- org.apache.lucene:lucene-highlighter:jar:5.5.4:compile
+- org.apache.lucene:lucene-queryparser:jar:5.5.4:compile
| \- org.apache.lucene:lucene-sandbox:jar:5.5.4:compile
+- org.apache.lucene:lucene-suggest:jar:5.5.4:compile
| \- org.apache.lucene:lucene-misc:jar:5.5.4:compile
+- org.apache.lucene:lucene-join:jar:5.5.4:compile
| \- org.apache.lucene:lucene-grouping:jar:5.5.4:compile
+- org.apache.lucene:lucene-spatial:jar:5.5.4:compile
| +- org.apache.lucene:lucene-spatial3d:jar:5.5.4:compile
| \- com.spatial4j:spatial4j:jar:0.5:compile
+- com.google.guava:guava:jar:18.0:compile
+- org.elasticsearch:securesm:jar:1.0:compile
+- com.carrotsearch:hppc:jar:0.7.1:compile
+- joda-time:joda-time:jar:2.9.5:compile
+- com.fasterxml.jackson.core:jackson-core:jar:2.8.1:compile
+- com.fasterxml.jackson.dataformat:jackson-dataformat-smile:jar:2.8.1:compile
+- com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:jar:2.8.1:compile
+- com.fasterxml.jackson.dataformat:jackson-dataformat-cbor:jar:2.8.1:compile
+- org.yaml:snakeyaml:jar:1.15:compile
+- io.netty:netty:jar:3.10.6.Final:compile
+- com.ning:compress-lzf:jar:1.0.2:compile
+- com.tdunning:t-digest:jar:3.0:compile
+- org.hdrhistogram:HdrHistogram:jar:2.1.6:compile
+- commons-cli:commons-cli:jar:1.3.1:compile
\- com.twitter:jsr166e:jar:1.1.0:compile
仔细查看后,我发现 GlassFish 自身的依赖项泄漏到应用程序类路径中(并且 GF 使用较旧的 Guava)因此 Glassfish4.1 用户的修复将更新 /glassfish/modules 中的 guava.jar番石榴 19 版本。
使用此依赖项:
<dependency>
<groupId>org.glassfish.jersey.bundles.repackaged</groupId>
<artifactId>jersey-guava</artifactId>
<version>2.19</version>
</dependency>
由于解决这个问题需要干预 GF 自己的库并且容易出错,我搬到了 Tomcat 并且没有其他更改它工作正常。