we have couple of annotations, for springboot controller method. and these are mostly reused in multiple methods.
@Annotation1 @Annotation2 @Annotation3 public void someMethod()
@CompositeAnnotation public void someMethod()
Is there a way we can create a composite annotation ? I know we might as well add a new one which encapsulates these, but at times this is not possible.
Just trying to reuse these bunch as single or reduced to fewer ones.
Any help is appreciated
It’s possible to create a new annotation that will have all yours.
You can take a look at
@SpringBootApplication realization – it contains
@ComponentScan annotations on self, so all of them are applied when
@SpringBootApplication is used.
@RestController which combines
In your case:
@Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) @Annotation1 @Annotation2 @Annotation3 public @interface CompositeAnnotation
Here is some tutorial: https://chrysanthium.com/spring-annotation-composition