javax.servlet.ServletException:资源配置类com.mypkg.MyClass不是类javax.ws.rs.core.Application的子类

时间:2018-10-25 12:02:57

标签: rest jersey jax-rs jersey-2.0 tomcat8.5

当尝试用Tomcat 8.5加载球衣类时出现此错误

25-Oct-2018 16:02:16.635 SEVERE [https-jsse-nio-8443-exec-3] org.apache.catalina.core.StandardWrapperValve.invoke Allocate exception for servlet [RESTFulWebNMS servlet]
 javax.servlet.ServletException: Resource configuration class com.mypkg.MyClass is not a subclass of class javax.ws.rs.core.Application.
    at org.glassfish.jersey.servlet.WebComponent.createResourceConfig(WebComponent.java:461)
    at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:301)
    at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:169)
    at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:359)
    at javax.servlet.GenericServlet.init(GenericServlet.java:158)
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1144)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1091)
    at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:773)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:133)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:800)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:800)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1471)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)

我链接到代码的依赖项在下面

${tp_pkg}/jersey/jaxrs_ri_2_8/jaxrs_ri/lib/jersey-client.jar:
${tp_pkg}/jersey/jaxrs_ri_2_8/jaxrs_ri/lib/jersey-common.jar:
${tp_pkg}/jersey/jaxrs_ri_2_8/jaxrs_ri/lib/jersey-container-servlet-core.jar:
${tp_pkg}/jersey/jaxrs_ri_2_8/jaxrs_ri/lib/jersey-container-servlet.jar:
${tp_pkg}/jersey/jaxrs_ri_2_8/jaxrs_ri/lib/jersey-server.jar:
${tp_pkg}/jersey_guava/jersey_guava_2_7/jersey-guava-2.7.jar:
${tp_pkg}/jersey_media/jersey_media_2_7/jersey-media-sse-2.7.jar:
${tp_pkg}/jersey/jaxrs_ri_2_8/jaxrs_ri/api/javax.ws.rs-api-2.0.jar

Web.xml条目是

<servlet>
                                <servlet-name>RESTFul servlet </servlet-name>
                                <servlet-class> org.glassfish.jersey.servlet.ServletContainer </servlet-class>
                                <init-param>
                                        <param-name> javax.ws.rs.Application</param-name>
                                        <param-value>com.mypkg.MyClass</param-value>
                                </init-param>
                                <load-on-startup> 1 </load-on-startup>
                                <async-supported> true </async-supported>
                      </servlet>
<servlet-mapping>
                        <servlet-name> RESTFul servlet </servlet-name>
                        <url-pattern> /rest/* </url-pattern>
                   </servlet-mapping>

配置类是

package com.mypkg
import org.glassfish.jersey.server.ResourceConfig;
public class MyClass extends ResourceConfig 
{
     public MyClass()
     {
          System.out.println("Successfully Registered");
     }
}

非常感谢您的帮助。谢谢。

0 个答案:

没有答案