JBOSS 7.1.0 error - Unable to find a public constructor for class org.jboss.resteasy.core.AsynchronousDispatcher

安稳与你 提交于 2019-12-03 12:13:00

I'm far from a REST expert, but javax.ws.rs.core.Application is not a servlet.

I have also seen this exception when using RESTEasy on JBoss 7.1.1 (without Spring). It was wrapped like this:

Allocate exception for servlet [project class reference]: java.lang.RuntimeException: Unable to find a public constructor for class org.jboss.resteasy.core.AsynchronousDispatcher

The solution was to exclude all RESTEasy jars from the war. In Maven, you can do this by ensuring any required RESTEasy dependencies are declared with Maven's 'provided' scope, as these are provided by JBoss, and excluding any transitive RESTEasy dependencies (see this link for an example). You can check if you have any RESTEasy dependencies by changing to the directory containing your pom.xml and issuing a command such as:

mvn dependency:tree | grep "resteasy"

If you are using your web.xml for JAX-RS activation, you may also need to switch to the class-based approach demonstrated in the RESTEasy docs. These solutions to this issue are mentioned by a RESTEasy developer here and here.

The problem is not the way RESTful service are declared, that way is quite standard for JAX-RS 1.1 (nothing to do with Servlet James !!), but it's a bug in JBoss, you need to specify the RESTful resources inside an Application subclass, otherwise it will try to mount AsyncDisp*** as a RESTful service.

I solved this problems by doing the following steps:

Step 1. Create your service registration class

public class RESTApplication extends javax.ws.rs.core.Application {

private Set<Object> singletons = new HashSet<Object>();

public RESTApplication () {
    singletons.add(new RestService());
}

@Override
public Set<Object> getSingletons() {
    return singletons;
}

}

Step 2: Edit your web.xml

<!-- Resteasy -->
<context-param>
    <param-name>resteasy.servlet.mapping.prefix</param-name>
    <param-value>/rest</param-value>
</context-param>

<servlet>
    <servlet-name>resteasy-servlet</servlet-name>
    <servlet-class>
        org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
            </servlet-class>
    <init-param>
        <param-name>javax.ws.rs.Application</param-name>
        <param-value>yourpackage.RESTApplication</param-value>
    </init-param>
</servlet>

<servlet-mapping>
    <servlet-name>resteasy-servlet</servlet-name>
    <url-pattern>/rest/*
    </url-pattern>
</servlet-mapping>   
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!