简体   繁体   English

Spring boot自定义注释..找出它的使用位置

[英]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. 我有一个自定义的弹簧启动注释,作为基于Spring启动的JAR应用程序的一部分提供,因此使用注释我的包扫描也会被触发。 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注释的类。

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. 其他用例取决于值,我需要生成不同的bean集。

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 ? 一般来说,我知道我们必须编写一个可以作为注释解析器并进行活动的类,Spring是否提供了编写这些注释解析器的任何东西?

Thanks in advance for your answers ! 提前感谢您的回答!

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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