简体   繁体   中英

How to avoid using the Path annotation

I have a bunch of web services with a very simple structure:

@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/method2 -> classA.method2

/someprefix/classB/method1 -> classB.method1

/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. It is error prone.

I searched around and tried multiple things, but nothing seems to work. I am using Apache CXF.

The Path Annotation is part of the API specification!

"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."

"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."

See here: 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.

So i am sorry you cannot do this without the Path Annotation!

Hope this helps ^^

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM