码迷,mamicode.com
首页 > 编程语言 > 详细

spring Mvc jersey配置

时间:2014-10-11 16:05:46      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:spring   jersey   

第一步:引入依赖的jar包

<!-- jersey -->
<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-client</artifactId>
    <version>${jersey.version}</version>
</dependency>
<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-server</artifactId>
    <version>${jersey.version}</version>
</dependency>
<dependency>
    <groupId>com.sun.jersey.contribs</groupId>
    <artifactId>jersey-spring</artifactId>
    <version>${jersey.version}</version>
    <exclusions>
        <exclusion>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.springframework</groupId>
            <artifactId>spring</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<!--jersey end-->

第二步:配置web.xml

<!--Jersey webservice -->
<servlet>
    <servlet-name>Jersey Spring Web Application</servlet-name>
    <servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
    <init-param>
        <param-name>com.sun.jersey.config.property.resourceConfigClass</param-name>
        <param-value>com.sun.jersey.api.core.PackagesResourceConfig</param-value>
    </init-param>
    <init-param>
        <param-name>com.sun.jersey.config.property.packages</param-name>
        <param-value>com.tjs.mymvc.webservices</param-value>
    </init-param>
    <load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Jersey Spring Web Application</servlet-name>
    <url-pattern>/webservices/*</url-pattern>
</servlet-mapping>

第三步:启动tomcat

可能会出现以下异常:com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not contain any root resource classes.

可能原因:查看com/tjs/mymvc/webservices/下是否创建了启动资源的类,要确保已创建。

本文出自 “javaruler” 博客,请务必保留此出处http://tengjs.blog.51cto.com/5641106/1562507

spring Mvc jersey配置

标签:spring   jersey   

原文地址:http://tengjs.blog.51cto.com/5641106/1562507

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!