2010-11-17 76 views
2

我在我的Spring配置的Web服務應用程序中有兩個簡單的資源類。根一(/報道)正常工作一段時間後,所有的路徑返回404.這是資源類:澤西與春天總是給子資源404

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"; 
    } 
} 

和子資源是在這裏:

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"; 
    } 
} 

我部署應用程序在一個稱爲factorlab-ws的webapp中的Jetty。 curl http://localhost:8080/factorlab-ws/reports會產生成功。但curl http://localhost:8080/factorlab-ws/reports/testitem給出了404狀態。

此外,我在ReportsResouce中的每個方法中放置斷點。 getTestText()打破罰款,但getTimelineResource()不,暗示它永遠不會進入該方法。

我可能會錯過什麼?

回答

0

我想出了這個問題 - 它在我的web.xml中。我爲Jersey Spring servlet配置了幾個servlet映射的路徑,但那不起作用。什麼工作是:

<servlet-mapping> 
    <servlet-name>jersey-spring</servlet-name> 
    <url-pattern>/</url-pattern> 
</servlet-mapping> 

我無法得到任何其他映射工作 - 給我404除了顯式的url模式的一切。所以,這解決了我的問題,但有誰知道這是否是一個錯誤?或者有什麼理由爲什麼這應該是它的工作方式?

+0

「/」的url-pattern不適用於我;但是,啓用跟蹤https://blogs.oracle.com/sandoz/entry/tracing_in_jersey會很有幫助。 – 2012-06-25 17:51:09