【问题标题】:Resteasy not working with @ApplicationPathResteasy 不适用于 @ApplicationPath
【发布时间】:2012-12-20 05:35:35
【问题描述】:

我无法使用简单的@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!";
  }
}

在“/uri-context/rest/test/”上请求会引发 404。使用 Jersey 一切都可以无缝运行。由于这是 JAX-RS 的一个非常微不足道的部分,这是怎么回事?

目前我只使用了 4 个我需要的 Resteasy 库:

  • async-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 除外)放在一起,也不能解决问题。

【问题讨论】:

  • 你说使用 Jersey 可以工作,但你没有说你想使用什么而不是 Jersey 不起作用。
  • 这是基本的 URL/URI 调用。
  • 您是否按照RESTEasy Installation Configuration 进行了正确的配置?您能否再描述一下您的设置(应用程序服务器、web.xml 等)?

标签: jax-rs resteasy


【解决方案1】:

注意 Jax-RS 1.0、pathslash

@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.

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

【讨论】:

  • 您先生,我的英雄!我的方法路径前面有一个斜线。何时使用斜线对我来说都是非常模糊的......
  • 哦,杀了我,现在就杀了我。
猜你喜欢
  • 2015-02-12
  • 2020-09-08
  • 2014-10-29
  • 1970-01-01
  • 2015-03-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多