0

So this will be mostly code to illustrate the issue, but issue as follows:

pointing my browser to localhost:8080/licsrv/items return 404.

revelant web.xml

<!-- Java Remoting Servlet -->
    <servlet>
        <servlet-name>licenseGenService</servlet-name>
        <servlet-class>org.springframework.web.context.support.HttpRequestHandlerServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>licenseGenService</servlet-name>
        <url-pattern>/remoting/licensing</url-pattern>
    </servlet-mapping>

    <!-- Restful API Servlet-->
    <servlet>
        <servlet-name>licensingRestService</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>
                mypackage.rest
            </param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>licensingRestService</servlet-name>
        <url-pattern>/orders</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>licensingRestService</servlet-name>
        <url-pattern>/items</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>licensingRestService</servlet-name>
        <url-pattern>/customers</url-pattern>
    </servlet-mapping>

ItemsResourceImpl.java

@Path("/items")
public class ItemsResourceImpl implements ItemsResource 
{

@GET
    @Produces("text/html")
    public String testItems()
    {
        return "<html><body><h1>Items Resource Tester</h1><p>Items Resource is available.</p></body></html>";
    }

.....
}

And then I have the bean in my applicationContext.xml

Now ItemsResource (an interface) also has annotations and methods defined, could this be the issue? My impression was that Jax-RS annotations are not inherited. Is it the fact that I have two servlets and am missing something? I have a pure REST service with just one servlet and same configuration doing the same thing. Depending on how I change the configuration I get 405 Method Not Allowed out of it as well. Any ideas?

4

2 回答 2

1

尝试访问http://localhost:8080/licsrv/items/items. 注释定义了相对于应用程序根的@Path路径(由 web.xml 中的 servlet 映射定义)。

于 2012-09-28T20:10:03.363 回答
0

servlet 映射对我来说很可疑。我不熟悉spring,但如果servlet映射是这样的:

<servlet-mapping>
    <servlet-name>licensingRestService</servlet-name>
    <url-pattern>/orders/*</url-pattern>
</servlet-mapping>

url 应该像: localhost:8080/licsrv/orders/items,具有相同的ItemsResourceImpl实现。

于 2012-09-27T18:59:04.237 回答