Resteasy无法使用@ApplicationPath

时间:2013-01-06 06:21:39

标签: jax-rs resteasy

我无法使用简单的@ApplicationPath注释让JAX-RS使用Resteasy 2.3.5。这是我正在使用的代码:

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

请求&#34; / uri-context / rest / test /&#34;投掷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除外)也无法解决问题。

1 个答案:

答案 0 :(得分:3)

请注意 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中,规范DOES表示@ApplicationPath@Path中的前导和尾随斜杠将被忽略。

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

对于我在Jersey 2和Resteasy上测试的内容,现在已经得到了尊重。

相关问题