xetra11
xetra11

Reputation: 8835

Rest endpoint defined in annotation

I'm using a bunch of microservices in my project. These microservices all share one common endpoint that returns an object which has been parsed through XML.

Now I'd love to have some kind of default method defined within the Annotation like this:

@RestController
public @interface ComaModule {
  Class<? extends Object> clazz();

  @RequestMapping("/descriptor")
   default ModuleDescriptor getDescriptor() {
    ModuleXmlUnmarshaller moduleXmlUnmarshaller = new ModuleXmlUnmarshaller(clazz());
    Optional<ModuleDescriptor> moduleDescriptorOptional = moduleXmlUnmarshaller.findModuleDescriptor();
    return moduleDescriptorOptional.orElse(null);
  }
}

That does not work since I am not able to have a method definition in my annotation. So the hard stuff is that I want to keep @RequestMapping("/descriptor") for this.

In fact I want some kind of aspect for every RestController I use. I read about AOP for Spring and Proxy but thought I might be able to achieve this with Annotations.

Upvotes: 0

Views: 238

Answers (1)

Rai
Rai

Reputation: 136

May be you can try adding annotation processor class, where you can write the code which have in your post and achieve what your goal.

Upvotes: 1

Related Questions