users@jersey.java.net

Re: Jersey with Spring always giving 404 for subresources

From: Suneel Marthi <suneel_marthi_at_yahoo.com>
Date: Wed, 17 Nov 2010 11:44:43 -0800 (PST)

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?