I would like to define a custom annotation and use it with an Inject annotation in below manner. How to access the annotation value inside injected bean ?
Annotation Definition,
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface CustomAnnotation{
String name();
}
Access annotation properties inside a 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),
@Inject
@CustomAnnotation("abc")
Processor myProcessor;
public void test()
{
myProcessor.process(); // myProcessor will behave based on value "abc"
}
you can follow the link for @CustomAnnotation
:-
http://www.javatechblog.com/java/how-to-create-custom-annotation-in-java/
https://www.mkyong.com/java/java-custom-annotations-example/
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.