org.jboss.resteasy.plugins.server.servlet.HttpServ

2019-08-03 17:56发布

问题:

I am using rest web service and building the project with maven. The project is building successfully, but when i hit url to test rest web services I am getting following exception.

java.lang.ClassCastException: org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher cannot be cast to javax.servlet.Servlet
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1116)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:809)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129)
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:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:745)

By googling(Google probably has become a verb :D) i found that the issue is related to jboss as7, so i tried to changed my pom.xml to lower version for resteasy. However the problem still persists. Here is what my web.xml now looks like....

<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-jaxrs</artifactId>
    <version>2.3.7.Final</version>
</dependency>


<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-jaxb-provider</artifactId>
    <version>3.0.4.Final</version>
</dependency>

<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-servlet-initializer</artifactId>
    <version>3.0.6.Final</version>
</dependency>

<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-jettison-provider</artifactId>
    <version>3.0.4.Final</version>
</dependency>

How can i fix this bug?

回答1:

All of those dependencies are provided by the server and should be marked as <scope>provided</scope>. You also don't need the org.jboss.resteasy:resteasy-servlet-initializer when running on WildFly, JBoss AS 7.x or JBoss EAP 6.x.

In the documentation it states the resteasy-servlet-initializer is only needed in containers that are not WildFly or JBoss AS/EAP containers.