java - 有没有类似 spring-hateoas 的 AnnotationMappingDiscoverer for RESTEasy 的东西?

标签 java resteasy spring-hateoas

当使用Spring的HATEOAS支持时,我真的很喜欢AnnotationMappingDiscoverer这有助于避免在测试中硬编码 REST 资源路径。有了它,我可以做类似的事情

discoverer = new AnnotationMappingDiscoverer(RequestMapping.class);
Method method = MyController.class.getMethod("myResourceMethod", params);
String path = discoverer.getMapping(method);

然后使用该路径作为测试中的资源路径。比测试中​​必须与 Controller 类和方法注释保持同步的硬编码路径要好得多。

RESTEasy 有类似的东西吗?

最佳答案

您可以使用UriBuilder :

假设以下类(class):

@Path("persons")
public class PersonResource {

    @Path("/{id}")
    public Response get(@PathParam("id") String id) {
      //
    }

}

你会得到这样的路径:

URI path = UriBuilder.fromResource(PersonResource.class)
                     .path(PersonResource.class, "get")
                     .build("4711");
// path = /persons/4711

关于java - 有没有类似 spring-hateoas 的 AnnotationMappingDiscoverer for RESTEasy 的东西?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33041944/

相关文章:

java - 如何从 Hibernate 配置获取数据源

java - 如何在rest webservice中接收编码的字节数组并对其进行解码并在java中另存为图像

java - 无法为 spring Controller 编码(marshal)类型、XML 输出

basic-authentication - 使用 Resteasy 客户端进行基本身份验证

java - 使用 Spring Hateoas 可分页

spring - 如何编写在 spring-data-hatoas 中公开资源或资源列表的分页 Controller

java - Apache Jersey 异常 :java. lang.NoSuchMethodError : org. glassfish.hk2.utilities.AbstractActiveDescriptor

java - Java 中一个线程可以同时调用两个锁的 wait() (6)

java - Hashmap 使用 [Ljava.lang.Long; 存储值

java - Jettison 和 JAXB 自动更改 JSON 响应中的数据类型