9

您好,当我尝试从我的 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.
    }

谢谢!

4

1 回答 1

18

这是你的类路径,你需要 httpmime-4.0.jar

于 2012-05-13T15:17:50.257 回答