3.2.3. JAX-RS and RESTEasy Changes

3.2.3.1. Configure JAX-RS and RESTEasy Changes

JBoss Enterprise Application Platform 6 automatically sets up RESTEasy, so you do not need to configure it yourself. Therefore, you should remove all of the existing RESTEasy configuration from your web.xml file and replace it with one of the following three options:

  1. Subclass javax.ws.rs.core.Application and use the @ApplicationPath annotation.
    This is the easiest option and does not require any xml configuration. Simply subclass javax.ws.rs.core.Application in your application and annotate it with the path where you want to make your JAX-RS classes available. For example:
    @ApplicationPath("/mypath")
    public class MyApplication extends Application {
    }
    
    In the above example, your JAX-RS resources are available in the path /MY_WEB_APP_CONTEXT/mypath/.

    Note

    Note the path should be specified as /mypath, not /mypath/*. There should be no trailing forward-slash or asterisk.
  2. Subclass javax.ws.rs.core.Application and use the web.xml file to set up the JAX-RS mapping.
    If you do not wish to use the @ApplicationPath annotation, you still need to subclass javax.ws.rs.core.Application. You then set up the JAX-RS mapping in the web.xml file. For example:
    public class MyApplication extends Application {
    }
    
    <servlet-mapping>
       <servlet-name>com.acme.MyApplication</servlet-name>
       <url-pattern>/hello/*</url-pattern>
    </servlet-mapping>
    In the above example, your JAX-RS resources are available in the path /MY_WEB_APP_CONTEXT/hello.

    Note

    You can also use this approach to override an application path that was set using the @ApplicationPath annotation.
  3. Modify the web.xml file.
    If you do not want to subclass Application, you can set up the JAX-RS mapping in the web.xml file as follows:
    <servlet-mapping>
       <servlet-name>javax.ws.rs.core.Application</servlet-name>
       <url-pattern>/hello/*</url-pattern>
    </servlet-mapping>
    In the above example, your JAX-RS resources are available in the path /MY_WEB_APP_CONTEXT/hello.

    Note

    When you choose this option, you only need to add the mapping. You do not need to add the corresponding servlet. The server is responsible for adding the corresponding servlet automatically.