2014-01-10 50 views
1

嘗試在我的WebApp中包含Elasticsearch java客戶端時出現問題。我有需要的依賴,我在初始化創建客戶端(作爲一個簡單的測試)/破壞的Spring bean,像這樣:在Spring WebApp中使用Elasticsearch客戶端時發生鏈接錯誤

@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應用程序所需的類,但將它安裝在不同的類加載器中。

我試着用ImmutableSettings明確設置由彈性搜索中使用的類加載器,但是這似乎沒有什麼差別:

ClassLoader contextClassLoader = thread.getContextClassLoader(); 
    try { 
     //thread.setContextClassLoader(ClassLoader.getSystemClassLoader()); 
     Settings s = ImmutableSettings.settingsBuilder() 
       .classLoader(contextClassLoader) 
       .build(); 

任何幫助,將不勝感激!謝謝!

+0

只需要一個與問題無關的註釋,您可以查看https://github.com/dadoonet/spring-elasticsearch獲取彈性搜索的彈簧工廠。 – dadoonet

+0

嗨,謝謝dadoonet - 你的項目是我的第一選擇,但我有同樣的問題,這就是爲什麼我使用這個精簡版來隔離問題。當我解決它時,我會切換到你的工廠。 –

回答

1

好吧,設法解決這個問題:

得到一個裁判tomcat的「共同」類加載器,並通過這個給Elasticsearch客戶端:

ClassLoader contextClassLoader = thread.getContextClassLoader(); 
try { 
     Settings settings = ImmutableSettings.settingsBuilder().classLoader(contextClassLoader.getParent()).build();    
     client = new TransportClient(settings); 

這樣做的副作用是,該名.txt文件必須從elasticSearch jar中移動到'common'類路徑上的某處。

我還沒有找到爲什麼這個問題影響我的特定堆棧而不是其他人,但是打算這樣做,並在這裏更新。

0

的解決方案是創建elastcisearch客戶端這樣的:

Settings settings = ImmutableSettings.settingsBuilder() 
.put(「path.plugins」, 「fakeDirectory:\\」) 
.build(); 

TransportClient client = new TransportClient(settings); 

我放個假目錄,因爲ElasticSearch使用它時,它開始加載所有的Eclipse插件,但我闖到大知道爲什麼! (請參閱org.elasticsearch.plugins.PluginsService類)。

相關問題