简体   繁体   English

如何避免使用路径注释

[英]How to avoid using the Path annotation

I have a bunch of web services with a very simple structure: 我有一堆具有非常简单结构的Web服务:

@Path("/someprefix"+"/classA")
public class ClassA {

    @Path(/method1)
    public ClassB method1(ClassC c) {

        ...

    }

}

Notice that there are no path params. 请注意,没有路径参数。 As you can see I always use the name of the class plus some prefix and the name of the method. 如您所见,我总是使用类的名称以及一些前缀和方法的名称。 For example: 例如:

/someprefix/classA/method1 -> classA.method1 / someprefix / classA / method1-> classA.method1

/someprefix/classA/method2 -> classA.method2 / someprefix / classA / method2-> classA.method2

/someprefix/classB/method1 -> classB.method1 / someprefix / classB / method1-> classB.method1

/someprefix/classB/method2 -> classB.method2 / someprefix / classB / method2-> classB.method2

I want to be able to produce the same structure without using the Path annotation, since I don't want to duplicate the name of the class/method every time. 我希望不使用Path注释就能产生相同的结构,因为我不想每次都重复类/方法的名称。 It is error prone. 这很容易出错。

I searched around and tried multiple things, but nothing seems to work. 我四处搜寻并尝试了多种方法,但似乎没有任何效果。 I am using Apache CXF. 我正在使用Apache CXF。

The Path Annotation is part of the API specification! 路径注释是API规范的一部分!

"Root resource class A resource class annotated with @Path . Root resource classes provide the roots of the resource class tree and provide access to sub-resources, see Chapter 3." “根资源类用@Path注释的资源类。根资源类提供资源类树的根并提供对子资源的访问,请参阅第3章。”

"3.1 Resource Classes A resource class is a Java class that uses JAX-RS annotations to implement a corresponding Web resource. Resource classes are POJOs that have at least one method annotated with @Path or a request method desig- nator." “ 3.1资源类资源类是一个Java类,它使用JAX-RS批注来实现相应的Web资源。资源类是POJO,它们至少具有一个用@Path注释的方法或请求方法标识符。”

See here: http://download.oracle.com/otndocs/jcp/jaxrs-2_0-fr-eval-spec/ 参见此处: http : //download.oracle.com/otndocs/jcp/jaxrs-2_0-fr-eval-spec/

And as pointed out here Adding Java Annotations at Runtime it is not possible to add annotations at runtime. 并且如此处所指出的, 在运行时添加Java注释是不可能在运行时添加注释的。

So i am sorry you cannot do this without the Path Annotation! 因此,很抱歉,如果没有路径注释,您将无法执行此操作!

Hope this helps ^^ 希望这可以帮助^^

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用@NamedEntityGraphs 注解时如何避免“代码异味”? - How to avoid “code smell” when using @NamedEntityGraphs annotation? 使用冒号时,将类@Path注释连接到方法@Path注释 - Concatenate class @Path annotation to method @Path annotation when using colon 如何避免重试添加测试注释? - How to avoid Retry adding in Test annotation? 我想在jetty中同时使用@WebServlet注释和@Path注释 - I want to using @WebServlet annotation and @Path annotation to same time in jetty 使用resteasy @Path注释时出现NoClassDefFoundError - NoClassDefFoundError when using resteasy @Path annotation 在Jersey中使用JaxRS @Path注释匹配最后一个路径元素 - Match last path element using JaxRS @Path annotation in Jersey 如何使用反射在“src/test”路径中列出所有用特定注释注释的方法? - How to list all methods annotated with specific annotation in "src/test" path using Reflections? 如何在Rest API Java中指定路径注释以接受任何路径? - How to specify path annotation in rest api java to accept any path? ObjectMapper避免注释 - ObjectMapper avoid annotation 在JAXB中编组时如何避免根元素注释? - How to avoid root element annotation while marshalling in JAXB?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM