休息java类不是要求新的泽西版

时间:2014-06-23 05:06:31

标签: rest jersey jersey-2.0

我正在尝试使用最新版本的球衣制作简单的演示休息应用程序。我可以使用旧版本(1.x)成功拨打休息电话。但我不知道,我不能为新版本制作它。 下面是我的pom.xml文件..我错过了一些依赖吗?

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>TestProject</groupId>
    <artifactId>TestProject</artifactId>
    <version>1.0</version>
    <packaging>war</packaging>
    <properties>
        <jersey.version>2.9</jersey.version>
    </properties>

    <dependencies>

       <!-- <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-core</artifactId>
            <version>1.17.1</version>
        </dependency>-->

        <dependency>
            <groupId>org.glassfish.jersey.core</groupId>
            <artifactId>jersey-server</artifactId>
            <version>${jersey.version}</version>
        </dependency>

        <dependency>
            <groupId>org.glassfish.jersey.core</groupId>
            <artifactId>jersey-common</artifactId>
            <version>${jersey.version}</version>
        </dependency>

        <dependency>
            <groupId>org.glassfish.jersey.core</groupId>
            <artifactId>jersey-client</artifactId>
            <version>${jersey.version}</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.0.1</version>
            <scope>provided</scope>
        </dependency>
   </dependencies>
</project>
下面的

是我的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>Restful Web Application</display-name>

    <servlet>
        <servlet-name>jersey-serlvet</servlet-name>
        <servlet-class><!--com.sun.jersey.spi.container.servlet.ServletContainer-->
            org.glassfish.jersey.servlet.ServletContainer
        </servlet-class>
        <init-param>
            <param-name><!--com.sun.jersey.config.property.packages-->
                jersey.config.server.provider.packages
            </param-name>
            <param-value>com.test.rest</param-value>
        </init-param>
        <init-param>
            <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
            <param-value>true</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>jersey-serlvet</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>

</web-app>

和Java文件如下

@Path("/hello")
public class HelloWorldService {

    @GET
    @Path("/test")
    public Response getMsg( @NotNull @QueryParam("name") String name) {
        String output = "Name : " + name;
        return Response.status(200).entity(output).build();
    }
}

我缺少什么?

0 个答案:

没有答案