Jersey集成到Spring的应用

13年前
(1)看看web.xml文件
<web-app id="WebApp_ID" version="2.4"   xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">     <display-name>JerseySpring</display-name>     <!-- 加载spring的配置 -->   <context-param>    <param-name>contextConfigLocation</param-name>    <param-value>classpath:applicationContext.xml</param-value>   </context-param>   <!-- 对Spring容器进行实例化 -->   <listener>    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>   </listener>   <listener>    <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>   </listener>     <servlet>    <servlet-name>JerseySpring</servlet-name>    <servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>        <init-param>     <param-name>com.sun.jersey.config.property.packages</param-name>     <param-value>ningbo.media.rest</param-value>    </init-param>    <load-on-startup>1</load-on-startup>   </servlet>     <filter>    <filter-name>encodingFilter</filter-name>    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>    <init-param>     <param-name>encoding</param-name>     <param-value>utf-8</param-value>    </init-param>    <init-param>     <param-name>forceEncoding</param-name>     <param-value>true</param-value>    </init-param>   </filter>   <filter-mapping>    <filter-name>encodingFilter</filter-name>    <url-pattern>/*</url-pattern>   </filter-mapping>     <!--配置openSessionInViewFilter -->   <filter>    <filter-name>OpenSessionInViewFilter</filter-name>    <filter-class>     org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>   </filter>       <filter-mapping>    <filter-name>OpenSessionInViewFilter</filter-name>    <url-pattern>/*</url-pattern>   </filter-mapping>     <servlet-mapping>    <servlet-name>JerseySpring</servlet-name>    <url-pattern>/*</url-pattern>   </servlet-mapping>  </web-app>
(2)配置applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>  <beans xmlns="http://www.springframework.org/schema/beans"   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"   xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"   xsi:schemaLocation="http://www.springframework.org/schema/beans             http://www.springframework.org/schema/beans/spring-beans-3.0.xsd             http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd             http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd             http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">     <!-- 开启通过注释进行事务配置 -->   <context:annotation-config />   <!-- 开启通过注释进行组件注入 -->   <context:component-scan base-package="com.company" />   <!-- 加载属性文件 -->   <context:property-placeholder location="classpath:db.properties"/>      <import resource="application-db.xml"/>  </beans>
未完待继。