2013-01-06 32 views
1

我無法使用Resteasy 2.3.5使用簡單的@ApplicationPath註釋來獲取JAX-RS。這裏是我使用的代碼:Resteasy無法使用@ApplicationPath

@ApplicationPath("/rest") 
public class MyApplication extends Application { 
    @Override 
    public Set<Class<?>> getClasses() { 
    final Set<Class<?>> s = new HashSet<Class<?>>(); 
    s.add(ViewController.class); 
    return s; 
    } 
} 

@Path("/") 
public class ViewController { 
    @GET 
    @Path("/test") 
    public String test() { 
    return "Yes!"; 
    } 
} 

請求對「/ URI上下文/ REST /測試/」拋出了一個404使用新澤西一切工作的無縫連接。由於這是JAX-RS的一個非常微不足道的部分,發生了什麼問題?

目前我只用4庫RestEasy的的,我會要求:

  • 異步HTTP的servlet的3.0-2.3.5.Final.jar
  • JAXRS-API-2.3.5。 Final.jar
  • RestEasy的-JAXRS-2.3.5.Final.jar
  • scannotation-1.0.3.jar

然而,把所有的庫(除了RestEasy的-CDI-2.3.5。 Final.jar),a也沒有解決問題。

+0

你說使用澤西島它的作品,但你不說你想用什麼,而不是澤西島,它不工作。 – Torque

+0

這是基本的URL/URI調用。 – Quin

+0

您是否根據[RESTEasy Installation Configuration](http://docs.jboss.org/resteasy/docs/2.0.0.GA/userguide/html_single/index.html#Installation_Configuration)進行了適當的配置?你能描述一下你的設置(應用服務器,web.xml等)嗎? – Torque

回答

2

謹防與JAX-RS 1.0時,路徑斜線

@ApplicationPath("api") //NO slash 
public class MyApplication extends Application { 
} 

@Path("/users") // YES slash 
public class ViewController { 

    @GET 
    @Path("all") //NO slash 
    public String all() { 
    return "Yes!"; 
    } 
} 

通常以斜線的照顧使得它很快更好。


更新JAX-RS 2:

在JAX-RS 2,規範不會說,領導和@ApplicationPath@Path尾隨斜線將被忽略。

(3)If the resource class URI template does not end with a ‘/’ character 
then one is added during the concatenation. 

對於我用澤西島2和Resteasy進行的測試,現在已經得到了尊重。

+0

你先生,我的英雄!我在我的方法路徑前有一個斜線。當我使用斜線時,這一切都非常模糊...... –

相關問題