你好,当我尝试从我的servlet的get方法初始化HttpSolrServer时,我得到了这个奇怪的异常
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/MAVL].[Resteasy]- Servlet.service() for servlet Resteasy threw exception
org.jboss.resteasy.spi.UnhandledException: java.lang.NoClassDefFoundError: org/apache/http/entity/mime/content/ContentBody
at org.jboss.resteasy.core.SynchronousDispatcher.unwrapException(SynchronousDispatcher.java:345)
at org.jboss.resteasy.core.SynchronousDispatcher.handleApplicationException(SynchronousDispatcher.java:321)
at org.jboss.resteasy.core.SynchronousDispatcher.handleException(SynchronousDispatcher.java:214)
at org.jboss.resteasy.core.SynchronousDispatcher.handleInvokerException(SynchronousDispatcher.java:190)
at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:534)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:496)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:119)
at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208)
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55)
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.NoClassDefFoundError: org/apache/http/entity/mime/content/ContentBody
at com.polgar.dipl.index.SolrIndex.init(SolrIndex.java:48)
at com.polgar.dipl.index.SolrIndex.getInstance(SolrIndex.java:42)
at com.polgar.dipl.Articles.getRandomArticles(Articles.java:37)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:140)
at org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:255)
at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:220)
at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:209)
at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:519)
... 18 more
Caused by: java.lang.ClassNotFoundException: org.apache.http.entity.mime.content.ContentBody
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
... 30 more
第48行是我正在初始化solr服务器的地方:
server = new HttpSolrServer(url);
Solr作为同一个Tomcat实例上的另一个servlet运行。 我这样称呼它:
@GET
@Path("/test")
public String getTest() {
SolrIndex s = SolrIndex.getInstance();
s.query()
public class SolrIndex {
private static SolrIndex solrIndex = null;
private static String url = "http://localhost:8080/solr/";
public static HttpSolrServer server = null;
public static SolrIndex getInstance() {
if (server == null)
init();
return solrIndex;
}
private static void init() {
solrIndex = new SolrIndex();
server = new HttpSolrServer(url); //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
server.setSoTimeout(1000); // socket read timeout
server.setConnectionTimeout(1000);
server.setDefaultMaxConnectionsPerHost(20);
server.setMaxTotalConnections(50);
server.setMaxRetries(1); // defaults to 0. > 1 not recommended.
}
谢谢!
答案 0 :(得分:11)
这是你的类路径,你需要httpmime-4.0.jar