Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jersey 2.3.1 and spring integration compatibility issues

Tags:

jersey-2.0

I am trying to create restful service project setup which will use jersey and spring. i downloaded initially jersey1.8 dependent jars also i got jersey-spring-1.8 and i used com.sun.jersey.spi.spring.container.servlet.SpringServlet as jersey servlet and this setup worked well without any issues.

Now i was asked to use latest jersey version that is jersey2.3.1, so i downloaded jersey2.3.1 dependent jars like (jersey-container-servlet-core-2.3.1,jersey-container-servlet-2.3.1 etc). Now the problem is with jersey-spring which will have com.sun.jersey.spi.spring.container.servlet.SpringServlet, i downloaded jar from maven repository ie jersey-spring3-2.3.1.jar but it does not contain that above SpringServlet.So can any one please tell me what is the corresponding jersey-spring jar or am i missing anything here.

Note i tried to use jersey2.3.1 related jars with jersey-spring-1.8, but now i got exception saying com.sun.jersey.spi.container.servlet.ServletContainer is missing. so there is some jar compatible issue.

Can anyone tell me how to proceed with jersey2.3.1 and spring integration?

like image 871
Kalaiselvam M Avatar asked Oct 06 '13 07:10

Kalaiselvam M


3 Answers

The com.sun.jersey.spi.spring.container.servlet.SpringServlet has become now org.glassfish.jersey.servlet.ServletContainer

See this post https://www.codepedia.org/ama/restful-web-services-example-in-java-with-jersey-spring-and-mybatis/ for a complete explanation of Jersey2 and Spring 3 integration.

like image 111
ama Avatar answered Nov 06 '22 18:11

ama


in jersey 2.x and spring integration we can not define resources and providers in spring beans as we used to do in jersey 1.x and spring integration. look at the below links.

https://java.net/jira/browse/JERSEY-1957 https://jersey.java.net/documentation/latest/spring.html

so there is no com.sun.jersey.spi.spring.container.servlet.SpringServlet in jersey 2.x

like image 3
Kalaiselvam M Avatar answered Nov 06 '22 17:11

Kalaiselvam M


With Jersey 2.x, org.glassfish.jersey.servlet.ServletContainer would be servlet class to be used.

In addition to javax.ws.rs.Application as an init-param option to the servlet, one can also have jersey.config.server.provider.packages as its parameter.

Below is a code snippet, how it would be in web.xml :

<!-- Jersey Servlet -->
<servlet>
    <servlet-name>jersey-servlet</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
    <!-- Register resources and providers -->
    <init-param>
        <param-name>jersey.config.server.provider.packages</param-name>
        <param-value>com.jersey.series.spring.integration.service</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

And in Spring applicationContext.xml include :

<!-- scans packages to find and register beans within the application context -->
<context:component-scan base-package="com.jersey.series.spring.integration" />

Hope this helps.

like image 3
Mahesh Avatar answered Nov 06 '22 18:11

Mahesh