简体   繁体   中英

Spring boot custom annotation .. Find out where it is used

Sorry for a basic question, but i have not been able to find a example for my use case.

I have a custom spring boot annotation, delivered as part of a Spring boot based JAR app, so that using the annotation my package scan is also triggered. I now have a use case to extend my annotation with some optional parameters. How do I write a annotation parser where the class on which My annotation is written is not known to me.

My custom annotation looks like this,

@ComponentScan(basePackageClasses = {MySpringConfigClass.class})
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface @MyCustomAnnotation {
   boolean param1() default true;
   boolean param2() default true;
}

Consuming application, can put this in any class, at the class level and not at method level / field level.

I need to find out where this annotation is used, and with what values. Other use case is depending on the values, I need to generate different set of beans.

I read through various tutorials, but all examples I see are written for methods and where the class name is also known.

Can somebody please suggest an option. Also in general I know that we have to write a class which can act as annotation parser and do activities, does Spring provide anything for writing these annotation parsers ?

Thanks in advance for your answers !

使用方面查找所有注释,然后使用来自Rajith Pemabandu评论的逻辑。

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