尝试在我的WebApp中包含Elasticsearch java客户端时遇到问题。我有所需的依赖项,我正在初始化/销毁Spring bean中创建客户端(作为一个简单的测试),如下所示:
@Override
public void afterPropertiesSet() throws Exception {
try {
client = new TransportClient();
InetSocketTransportAddress addr = new InetSocketTransportAddress("localhost", 9300);
((TransportClient) client).addTransportAddress(addr);
}
catch(Exception e){
System.out.println(e.toString());
}
}
相应的destroy()将关闭客户端。
一切看起来都很好并且上下文开始正常但是在访问JSP时我收到以下异常:
SEVERE: Servlet.service() for servlet [jsp] in context with path [/Fountain] threw exception [Filter execution threw an exception] with root cause
java.lang.LinkageError: loader constraint violation in interface itable initialization: when resolving method "javax.servlet.ServletResponseWrapper.getOutputStream()Ljavax/servlet/ServletOutputStream;" the class loader (instance of org/apache/catalina/loader/WebappClassLoader) of the current class, javax/servlet/ServletResponseWrapper, and the class loader (instance of org/apache/catalina/loader/StandardClassLoader) for interface javax/servlet/ServletResponse have different Class objects for the type vlet/ServletOutputStream; used in the signature
at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:186)
at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:181)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:581)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)
Jan 10, 2014 10:44:46 AM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.LinkageError: loader constraint violation: when resolving method "javax.servlet.jsp.JspFactory.getPageContext(Ljavax/servlet/Servlet;Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;Ljava/lang/String;ZIZ)Ljavax/servlet/jsp/PageContext;" the class loader (instance of org/apache/jasper/servlet/JasperLoader) of the current class, org/apache/jsp/jsp/ajaxerror_jsp, and the class loader (instance of org/apache/catalina/loader/StandardClassLoader) for resolved class, javax/servlet/jsp/JspFactory, have different Class objects for the type t/ServletRequest;Ljavax/servlet/ServletResponse;Ljava/lang/String;ZIZ)Ljavax/servlet/jsp/PageContext; used in the signature
at org.apache.jsp.jsp.ajaxerror_jsp._jspService(ajaxerror_jsp.java:59)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:489)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:412)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339)
at org.apache.catalina.core.StandardHostValve.custom(StandardHostValve.java:467)
at org.apache.catalina.core.StandardHostValve.throwable(StandardHostValve.java:412)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:201)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)
Jan 10, 2014 10:44:46 AM org.apache.catalina.core.StandardHostValve custom
SEVERE: Exception Processing ErrorPage[exceptionType=java.lang.Throwable, location=/jsp/ajaxerror.jsp]
org.apache.jasper.JasperException: javax.servlet.ServletException: java.lang.LinkageError: loader constraint violation: when resolving method "javax.servlet.jsp.JspFactory.getPageContext(Ljavax/servlet/Servlet;Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;Ljava/lang/String;ZIZ)Ljavax/servlet/jsp/PageContext;" the class loader (instance of org/apache/jasper/servlet/JasperLoader) of the current class, org/apache/jsp/jsp/ajaxerror_jsp, and the class loader (instance of org/apache/catalina/loader/StandardClassLoader) for resolved class, javax/servlet/jsp/JspFactory, have different Class objects for the type t/ServletRequest;Ljavax/servlet/ServletResponse;Ljava/lang/String;ZIZ)Ljavax/servlet/jsp/PageContext; used in the signature
at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:549)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:489)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:412)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339)
at org.apache.catalina.core.StandardHostValve.custom(StandardHostValve.java:467)
at org.apache.catalina.core.StandardHostValve.throwable(StandardHostValve.java:412)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:201)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)
Caused by: javax.servlet.ServletException: java.lang.LinkageError: loader constraint violation: when resolving method "javax.servlet.jsp.JspFactory.getPageContext(Ljavax/servlet/Servlet;Ljavax/servlet/ServletR equest;Ljavax/servlet/ServletResponse;Ljava/lang/String;ZIZ)Ljavax/servlet/jsp/PageContext;" the class loader (instance of org/apache/jasper/servlet/JasperLoader) of the current class, org/apache/jsp/jsp/ajaxerror_jsp, and the class loader (instance of org/apache/catalina/loader/StandardClassLoader) for resolved class, javax/servlet/jsp/JspFactory, have different Class objects for the type t/ServletRequest;Ljavax/servlet/ServletResponse;Ljava/lang/String;ZIZ)Ljavax/servlet/jsp/PageContext; used in the signature
at org.apache.jsp.jsp.ajaxerror_jsp._jspService(ajaxerror_jsp.java:130)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
... 22 more
Caused by: java.lang.LinkageError: loader constraint violation: when resolving method "javax.servlet.jsp.JspFactory.getPageContext(Ljavax/servlet/Servlet;Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;Ljava/lang/String;ZIZ)Ljavax/servlet/jsp/PageContext;" the class loader (instance of org/apache/jasper/servlet/JasperLoader) of the current class, org/apache/jsp/jsp/ajaxerror_jsp, and the class loader (instance of org/apache/catalina/loader/StandardClassLoader) for resolved class, javax/servlet/jsp/JspFactory, have different Class objects for the type t/ServletRequest;Ljavax/servlet/ServletResponse;Ljava/lang/String;ZIZ)Ljavax/servlet/jsp/PageContext; used in the signature
at org.apache.jsp.jsp.ajaxerror_jsp._jspService(ajaxerror_jsp.java:59)
... 25 more
如果没有这个,上下文将启动并正确地为JSP提供服务。
有没有人有任何想法可能导致这个?我假设elasticsearch客户端正在使用web-app所需的类,但在不同的类加载器中进行实例化。
我尝试使用ImmutableSettings明确设置弹性搜索使用的类加载器,但这似乎没有任何区别:
ClassLoader contextClassLoader = thread.getContextClassLoader();
try {
//thread.setContextClassLoader(ClassLoader.getSystemClassLoader());
Settings s = ImmutableSettings.settingsBuilder()
.classLoader(contextClassLoader)
.build();
任何帮助将不胜感激!谢谢!
答案 0 :(得分:1)
好的,设法解决了这个问题:
获取tomcat'common'类加载器的引用并将其传递给Elasticsearch客户端:
ClassLoader contextClassLoader = thread.getContextClassLoader();
try {
Settings settings = ImmutableSettings.settingsBuilder().classLoader(contextClassLoader.getParent()).build();
client = new TransportClient(settings);
这样做的副作用是names.txt文件必须从elasticSearch jar移动到'common'类路径上的某个地方。
我仍然没有找到为什么这个问题影响我的特定堆栈,而不是其他人,但目的是这样做并在这里更新。
答案 1 :(得分:0)
解决方案是创建弹性网络客户端,如下所示:
Settings settings = ImmutableSettings.settingsBuilder()
.put(“path.plugins”, “fakeDirectory:\\”)
.build();
TransportClient client = new TransportClient(settings);
我放了一个假目录,因为ElasticSearch在开始加载所有eclipse插件时使用它,但我知道为什么!! (请参阅org.elasticsearch.plugins.PluginsService类)。