简体   繁体   中英

Custom annotation usage

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"
}

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