< dependency>
<groupId > org.glassfish.jersey.containers</ groupId >
<!-- if your container implements Servlet API
older than 3.0, use "jersey-container-servlet-core" -->
<artifactId > jersey-container-servlet </artifactId >
<version > 2.5</ version >
</ dependency>
<!-- Required only when you are using JAX-RS Client -->
< dependency>
< groupId> org.glassfish.jersey.core </groupId >
< artifactId> jersey-client </artifactId >
< version> 2.5 </version >
</ dependency>
< dependency>
< groupId> org.glassfish.jersey.ext </groupId >
< artifactId> jersey-spring3 </artifactId >
< version> 2.5 </version >
</ dependency>
<!-- <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.0.6.RELEASE</version>
<scope>compile</scope>
</dependency> -->
< dependency>
< groupId> commons-logging </groupId >
< artifactId> commons-logging </artifactId >
< version> 1.1 </version >
< exclusions>
< exclusion>
< groupId> javax.servlet </groupId >
< artifactId> servlet- api</ artifactId>
</ exclusion>
</ exclusions>
</ dependency>
< dependency>
< groupId> javax.servlet </groupId >
< artifactId> servlet- api</ artifactId>
< version> 2.5 </version >
</ dependency>
< listener>
< listener-class> org.springframework.web.context.ContextLoaderListener </ listener-class>
</ listener>
< context-param>
< param-name> contextConfigLocation </param-name >
< param-value> classpath:applicationContext.xml </param-value >
</ context-param>
<servlet >
< servlet-name> Jersey
REST Service </servlet-name >
< servlet-class> org.glassfish.jersey.servlet.ServletContainer </servlet-class >
<!--這裏只是其中一種暴漏資源的方式-->
< init-param>
< param-name> javax.ws.rs.Application </param-name >
< param-value> com.hpf.restfullservice.spring.Myapplication </param-value >
</ init-param>
< load-on-startup> 1</ load-on-startup >
</servlet >
<servlet-mapping >
< servlet-name> Jersey
REST Service </servlet-name >
< url-pattern> /rest/* </url-pattern >
</servlet-mapping >
Myapplication.java
import org.glassfish.jersey.server.ResourceConfig;
importorg.glassfish.jersey.server.spring.scope.RequestContextFilter;
public class Myapplication extends ResourceConfig{
public Myapplication(){
register(RequestContextFilter. class );
register(Hello. class );//註冊需要暴漏的資源
}
}
applicationContext.xml
< 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"
xsi:schemaLocation ="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd"
>
<!-- 開啓註解配置 -->
<context:annotation-config />
<!-- 對指定的包進行組件掃描 -->
<context:component-scan base-package= "com.hpf" />
</ beans>