簡體   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