繁体   English   中英

自定义注释用法

[英]Custom annotation usage

我想以以下方式定义自定义注释并将其与Inject注释一起使用。 如何访问注入的bean中的注释值?

注释定义,

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface CustomAnnotation{
    String name();
}

访问bean内的注释属性,

@Component
public class Processor {
    Would like to know the value "abc" in constructor/post-constructor. How to access name method here ?
}

测试用法(值“ abc”用于加载相应的配置并使Bean正常运行),

@Inject
@CustomAnnotation("abc")
Processor myProcessor;

public void test()
{
    myProcessor.process(); // myProcessor will behave based on value "abc"
}

暂无
暂无

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

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