[英]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.