users@jersey.java.net

Re: Jersey with Spring always giving 404 for subresources

From: Jason Erickson <jason_at_jasonerickson.com>
Date: Wed, 17 Nov 2010 12:10:23 -0800

That's not it.

That is a change from when I had an actual TimelineResource bean (I still do) but it was a much more complicated resource, so I subbed in this do-nothing one. Also, I'm not seeing any errors in the log about not being able to autowire the bean, which I would if it couldn't find it, right?

One other thing - even using a Spring bean as the downstream resource was a stab in the dark after simply creating a new TestItemResource and returning gave me the 404. I thought maybe it had to be a Spring Bean for the SpringServlet to figure something out, but that doesn't look like it was the problem.

In any case, I changed the name of the field to testItemResource and had no luck - same issue. Any other ideas?

On Nov 17, 2010, at 11:44 AM, Suneel Marthi wrote:

> I think the problem is with your autowiring.
>
> You have
>
> @Autowired
> private TestItemResource timelineResource;
>
> and by default Spring autowires 'ByName' and is expecting a bean with id = 'timelineResource'.
>
> Try this:-
>
> @Autowired
> @Qualifier("testItemResource")
> private TestItemResource timelineResource;
>
> OR
>
> @Autowired
> private TestItemResource testItemResource;
> @Path("testitem")
> public TestItemResource getTimelinResource() {
> return testItemResource;
> }
>
>
>
> From: Jason Erickson <jerickson_at_factorlab.com>
> To: users_at_jersey.java.net
> Sent: Wed, November 17, 2010 2:24:58 PM
> Subject: Jersey with Spring always giving 404 for subresources
>
> I have two simple resource classes in my Spring configured web service application. The root one (/reports) works correctly while any path after that returns a 404. Here are the resource classes:
>
> package com.factorlab.ws.reports;
>
> import javax.ws.rs.GET;
> import javax.ws.rs.Path;
> import javax.ws.rs.Produces;
> import javax.ws.rs.core.MediaType;
>
> import org.springframework.beans.factory.annotation.Autowired;
> import org.springframework.context.annotation.Scope;
> import org.springframework.stereotype.Component;
>
> @Component
> @Scope("prototype")
> @Path("reports")
> public class ReportsResource {
>
> @Autowired
> private TestItemResource timelineResource;
>
> @Path("testitem")
> public TestItemResource getTimelinResource() {
> return timelineResource;
> }
>
> @GET
> @Produces(MediaType.TEXT_PLAIN)
> public String getTestText() {
> return "Success!\n";
> }
> }
> And the sub-resource is here:
>
> package com.factorlab.ws.reports;
>
> import javax.ws.rs.GET;
> import javax.ws.rs.Produces;
> import javax.ws.rs.core.MediaType;
>
> import org.springframework.context.annotation.Scope;
> import org.springframework.stereotype.Component;
>
> @Component
> @Scope("prototype")
> public class TestItemResource {
>
> @GET
> @Produces(MediaType.TEXT_PLAIN)
> public String hello() {
> return "Success!\n";
> }
> }
> I deploy the application to Jetty in a webapp called factorlab-ws. curl http://localhost:8080/factorlab-ws/reports yields success. However curl http://localhost:8080/factorlab-ws/reports/testitem gives a 404 status.
>
> What could I be missing?
>
>
>