jersey 2.3.1 and spring integration compatibility issues

我是研究僧i 提交于 2019-12-06 01:49:47

问题


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?


回答1:


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

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




回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/19206466/jersey-2-3-1-and-spring-integration-compatibility-issues

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!