在调用我的api时,迁移到Jersey 2.x会出现404错误

时间:2016-03-18 00:23:38

标签: java web-services rest servlets jersey-2.0

我正在从com.sun.jersey 1.x迁移到org.glassfish.jersey 2.x,

我的web.xml看起来像:

     <?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

<!-- Bean Configuration -->
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:application-context.xml</param-value>
</context-param>

<context-param>
    <param-name>webAppRootKey</param-name>
    <param-value>webservices</param-value>
</context-param>

<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>jersey-servlet</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>

    <init-param>
        <param-name>jersey.config.server.provider.packages</param-name>
        <param-value>com.jersey.series.spring.security.service</param-value>
    </init-param>
    <init-param>
        <param-name>jersey.config.server.provider.packages</param-name>
        <param-value>com.xyz.webservices</param-value>
    </init-param>
    <!-- Enable / Disable Jersey Tracing and Logging. -->
    <init-param>
        <param-name>jersey.config.server.tracing</param-name>
        <param-value>${jersey.enable.trace}</param-value>
    </init-param>
    <init-param>
        <param-name>jersey.disable.wadl</param-name>
        <param-value>${jersey.disable.wadl}</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>jersey-servlet</servlet-name>
    <url-pattern>/api/*</url-pattern>
</servlet-mapping>

<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>

<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

所以在com.xyz.webservices.resources下定义的资源,每当被称为&#39; / app / api / data&#39;说找不到404页面。我在这里做错了吗?

1 个答案:

答案 0 :(得分:0)

我通过将我的web.xml修改为:

来使代码正常工作
    <init-param>
        <param-name>jersey.config.server.provider.packages</param-name>
        <param-value>com.jersey.series.spring.security.service,com.xyz.webservices</param-value>
    </init-param>

    <!-- Enable / Disable Jersey Tracing -->
    <init-param>
        <param-name>jersey.config.server.tracing</param-name>
        <param-value>${jersey.enable.trace}</param-value>
    </init-param>
    <init-param>
        <param-name>jersey.disable.wadl</param-name>
        <param-value>${jersey.disable.wadl}</param-value>
    </init-param>

    <!-- Enabling Jackson Feature and Logging -->
    <init-param>
        <param-name>jersey.config.server.provider.classnames</param-name>
        <param-value>org.glassfish.jersey.jackson.JacksonFeature,org.glassfish.jersey.filter.LoggingFilter,org.glassfish.jersey.server.filter.EncodingFilter,org.glassfish.jersey.message.DeflateEncoder,org.glassfish.jersey.message.GZipEncoder</param-value>
    </init-param>