Resteasy不与@ApplicationPath一起使用

编程入门 行业动态 更新时间:2024-10-27 17:10:15
本文介绍了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一起使用

本文发布于:2023-11-17 03:45:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1608704.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不与   Resteasy   ApplicationPath

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!