[英]Custom annotation usage
I would like to define a custom annotation and use it with an Inject annotation in below manner. 我想以以下方式定义自定义注释并将其与Inject注释一起使用。 How to access the annotation value inside injected bean ?
如何访问注入的bean中的注释值?
Annotation Definition, 注释定义,
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface CustomAnnotation{
String name();
}
Access annotation properties inside a bean, 访问bean内的注释属性,
@Component
public class Processor {
Would like to know the value "abc" in constructor/post-constructor. How to access name method here ?
}
Test Usage (The value "abc" is used to load respective configuration and make the bean behave appropriately), 测试用法(值“ abc”用于加载相应的配置并使Bean正常运行),
@Inject
@CustomAnnotation("abc")
Processor myProcessor;
public void test()
{
myProcessor.process(); // myProcessor will behave based on value "abc"
}
you can follow the link for @CustomAnnotation
:- 您可以点击
@CustomAnnotation
的链接:-
http://www.javatechblog.com/java/how-to-create-custom-annotation-in-java/ http://www.javatechblog.com/java/how-to-create-custom-annotation-in-java/
https://www.mkyong.com/java/java-custom-annotations-example/ https://www.mkyong.com/java/java-custom-annotations-example/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.