2017-06-17 176 views
0

我想定義一個自定義註釋,並以下面的方式將其與Inject註釋一起使用。如何訪問注入bean中的註釋值?豆內部自定義註釋用法

註釋定義,

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

訪問註釋屬性,

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

試驗使用(該值「ABC」是用來加載各自的配置,使豆的行爲適當地),

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

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

回答