[英]Accessing spring annotation attribute in method
這可能是一個奇怪的請求,但是有一種方法可以訪問方法本身中的Spring注釋屬性。
在下面的示例中,可以將“ user.success”定義為常量,並在“批注”和方法中使用它,但我真的很想使用在我的批注(@MySecurity)中定義的內容。
我想一種方法是獲取使用AnnotationUtils的執行方法的句柄。 有沒有更好,更優雅的方法?
@MySecurity(action="user.success")
@RequestMapping("/userSuccess.htm")
public String redirect()
{
// Code here to access @MySecurity Annotation
return "userSuccess";
}
不,沒有反射就不可能。 即使這樣,您也需要知道方法的名稱。 在其中執行代碼不會告訴您(堆棧跟蹤除外,但不要走那條路)。 老實說,注釋應該由HandlerInterceptor
(可以使用HandlerMethod
來訪問注釋)或某種BeanPostProcessor
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.