Java – Upgrading JAX-RS 1.1 to JAX-RS 2.0 need help on web.xml deployment

jakarta-eejavajax-rsjqueryrest

I am working on project to upgrade my existing web application which is developed in JAX-RS 1.12 and running in tomcat 7. Now I am upgrading it to JAX-RS2.0. During tomcat server startup my resources are not getting loaded ?

Below are the details.
Added below jars for JAX-RS 2.0

jersey-client-2.0-m07-1
jersey-common-2.0-m07-1
jersey-container-servlet-2.0-m07-1
jersey-container-servlet-core-2.0-m07-1
jersey-server-2.0-m07-1
javax.ws.rs-api-2.0-m10
osgi-resource-locator-1.0.1
javax.inject-2.1.28
javax.inject-1
hk2-utils-2.1.28
hk2-locator-2.1.28
hk2-api-2.1.28
guava-13.0
cglib-2.1.28
asm-all-repackaged-2.1.28

In Web.xml

<?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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>ConfigLiteJersey2</display-name>

<!-- Jersey Servlet to Support JAXRS Services -->
<servlet>
    <servlet-name>ConfigLiteServices</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>        
     <init-param>
        <param-name>javax.ws.rs.core.Application</param-name>
        <param-value>com.cisco.config.resource</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
     <servlet-mapping>
    <servlet-name>ConfigLiteServices</servlet-name>
    <url-pattern>/config/*</url-pattern>
</servlet-mapping>

My Resource File

@Path("/configset")
public class ConfigSetResource {   
    @POST
@Path("/id{configsetid: (/[^/]+?)?}")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public ConfigSetResponse getConfigSet(@PathParam("configsetid") String sConfigSetId)    throws    Exception {
     //Code
    }
    }

Trying to access my resource API using below URL
ipaddress:8080/ConfigLiteJersey2/config/configset/id

Getting HTTP status 404 Not found.

Looks like I am not giving right servletclass mapping in web.xml. Please share your thoughts on this

Best Answer

If you want Jersey to scan your package for resources, change your param-name to:

<param-name>jersey.config.server.provider.packages</param-name>
Related Topic