Resteasy不与@ApplicationPath一起使用 [英] Resteasy not working with @ApplicationPath

查看:127
本文介绍了Resteasy不与@ApplicationPath一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使用简单的@ApplicationPath注释使RestX 2.3.5与JAX-RS一起使用.这是我正在使用的代码:

I am not being able to get JAX-RS working with Resteasy 2.3.5 usingh simple @ApplicationPath annotation. Here is the code I am using:

@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的一个非常琐碎的部分,怎么了?

Requesting on "/uri-context/rest/test/" throws a 404. Using Jersey everything works seamlessly. Since this is a very trivial part of JAX-RS what's going on wrong?

目前,我仅使用4个需要的Resteasy库:

Currently I am using only 4 libs of Resteasy that I would require:

  • 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除外)也不能解决问题.

Nevertheless, putting all the libs (except for resteasy-cdi-2.3.5.Final.jar), also does not solve the problem.

推荐答案

请注意 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!";
  }
}

通常情况下,使用斜杠会使它很快变得更好.

Usually taking care of slashes makes it quickly better.

JAX-RS 2的更新:

UPDATE for JAX-RS 2 :

在JAX-RS 2中,规范确实说@ApplicationPath@Path中的前斜杠和后斜杠将被忽略.

In JAX-RS 2, the spec DOES says that leading and trailing slashes in @ApplicationPath or @Path will be ignored.

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

对于我在Jersey 2和Resteasy上进行的测试,现在已经尊重了.

For what I have tested with Jersey 2 and Resteasy, this is now respected.

这篇关于Resteasy不与@ApplicationPath一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆