deploying a RESTEasy JAX-RS app to JBoss - JBAS018040: Failed to start context

1.6k views Asked by At

I am trying to deploy a JAX-RS application to JBoss EAP 6.2. My web.xml has the following:

<servlet>
    <servlet-name>resteasy-servlet</servlet-name>
    <servlet-class>
        org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
    </servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>resteasy-servlet</servlet-name>
    <url-pattern>/jax-rs/*</url-pattern>
</servlet-mapping>


<context-param>
    <param-name>resteasy.servlet.mapping.prefix</param-name>
    <param-value>/jax-rs</param-value>
</context-param>

<listener>
    <listener-class>
        org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
    </listener-class>
</listener>

<context-param>
    <param-name>resteasy.scan</param-name>
    <param-value>true</param-value>
</context-param>

… and I include the following as a deployment dependency:

<dependency org="org.jboss.resteasy" name="resteasy-jaxrs" rev="3.0.5.Final"/>

… so I have the following JAR in my WAR:

WEB-INF/lib/resteasy-jaxrs-3.0.5.Final.jar

However, when I deploy the WAR to JBoss I get the following trace:

14:32:42,537 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 316) MSC000001: Failed to start service jboss.web.deployment.default-host./search-rest: org.jboss.msc.service.StartException in service jboss.web.deployment.default-host./search-rest: org.jboss.msc.service.StartException in anonymous service: JBAS018040: Failed to start context at org.jboss.as.web.deployment.WebDeploymentService$1.run(WebDeploymentService.java:96) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [rt.jar:1.8.0_111] at java.util.concurrent.FutureTask.run(FutureTask.java:266) [rt.jar:1.8.0_111] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_111] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_111] at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_111] at org.jboss.threads.JBossThread.run(JBossThread.java:122)

Caused by: org.jboss.msc.service.StartException in anonymous service: JBAS018040: Failed to start context at org.jboss.as.web.deployment.WebDeploymentService.doStart(WebDeploymentService.java:161) at org.jboss.as.web.deployment.WebDeploymentService.access$000(WebDeploymentService.java:60) at org.jboss.as.web.deployment.WebDeploymentService$1.run(WebDeploymentService.java:93) ... 6 more

What is going on and how can I debug this ?

1

There are 1 answers

0
Marcus Junius Brutus On

OK, so the culprit was the following jar:

WEB-INF/lib/resteasy-jaxrs-3.0.5.Final.jar

Once I removed that dependency, it worked. This makes sense as RESTEasy is bundled with JBoss EAP so there should be no need to place it in the WAR's WEB-INF/lib.

Also, I discovered that the following element from my web.xml:

<listener>
   <listener-class>
       org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
   </listener-class>
</listener>

… is not necessary. Everything works without it as well.

Finally an additional configuration that works is removing the scanner element:

<context-param>
   <param-name>resteasy.scan</param-name>
   <param-value>true</param-value>
</context-param>

… in which case however one has to provide a javax.ws.rs.core.Application subclass:

import java.util.Set;
import java.util.HashSet;

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

public class JaxRsApplication extends Application { 

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

 public JaxRsApplication() {
     singletons.add( new SearchResource() );
 }

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

… and register it with the RESTEasy servlet:

<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>mjb44.searchapp.rest.JaxRsApplication</param-value>
    </init-param>
</servlet>