Jersey 2 JBoss Tutorial

Create ApplicationConfig

Here we register the StudentController class, so that jersey will invoke properly

package com.config;

import org.glassfish.jersey.server.ResourceConfig;

import com.controller.StudentController;


public class ApplicationConfig extends ResourceConfig {

   
public ApplicationConfig() {
       
register(StudentController.class);
   
}
}

web.xml

JBoss already packed with it's own rest framework known as RESTEasy. In order to avoid the conflicts with Jersey, you need to explicitly turn off JBOSS RESTEasy scanning.

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns="http://java.sun.com/xml/ns/javaee" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
  <display-name>Jboss: Jersey</display-name>
  <context-param>
    <param-name>resteasy.scan</param-name>
    <param-value>false</param-value>
  </context-param>
  <context-param>
    <param-name>resteasy.scan.providers</param-name>
    <param-value>false</param-value>
  </context-param>
  <context-param>
    <param-name>resteasy.scan.resources</param-name>
    <param-value>false</param-value>
  </context-param>
  <servlet>
    <servlet-name>jersey</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<!-- specify the application configruation --> <init-param> <param-name>javax.ws.rs.Application</param-name> <param-value>com.config.ApplicationConfig</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>jersey</servlet-name> <url-pattern>/rest/*</url-pattern> </servlet-mapping> </web-app>

jboss-deployment-structure.xml

Even though we turn off JBOSS RESTEasy scanning, we need to create JBoss deployment descriptor because JBoss 6.2 includes dependencies of modules

<?xml version='1.0' encoding='UTF-8'?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
	<deployment>
		<exclude-subsystems>
			<subsystem name="resteasy" />
		</exclude-subsystems>
		<exclusions>
			<module name="javaee.api" />
			<module name="javax.ws.rs.api" />
			<module name="org.jboss.resteasy.resteasy-jaxrs" />
		</exclusions>
	</deployment>
</jboss-deployment-structure>

Publishing Jersey 2 JBoss Restful Service

Run Jersey Restful On JBoss

Jersey 2 Output

Jersey 2 response

Note

you can also see the examples of using GET and POST method Restful Client









Previous 1 2





Your email address will not be published. Required fields are marked *