通過 aop 寫 自定義註解

2021-09-25 19:25:17 字數 789 閱讀 4650

@target(elementtype.method)

@retention(retentionpolicy.runtime)

public @inte***ce iface1

@target:

@target說明了annotation所修飾的物件範圍:annotation可被用於 packages、types(類、介面、列舉、annotation型別)、型別成員(方法、構造方法、成員變數、列舉值)、方法引數和本地變數(如迴圈變數、catch引數)。在annotation型別的宣告中使用了target可更加明晰其修飾的目標。

@retention:

@retention定義了該annotation被保留的時間長短:某些annotation僅出現在源**中,而被編譯器丟棄;而另一些卻被編譯在class檔案中;編譯在class檔案中的annotation可能會被虛擬機器忽略,而另一些在class被裝載時將被讀取(請注意並不影響class的執行,因為annotation與class在使用上是被分離的)。使用這個meta-annotation可以對 annotation的「生命週期」限制。

@aspect

@component

public class aspect11

@afterreturning(pointcut="advice()", returning="result")

public void afterreturning(joinpoint jp, object result) );}}

}

AOP 自定義註解

compile org.springframework.boot spring boot starter aop aspect component public class auditaspect before weblog public void debefore joinpoint joinpo...

自定義註解AOP

專案中有些模組需要加入工作流審批流程,並且可以選擇是否開啟工作流。於是根據需求就想到了用aop做乙個通用的模組開關檢驗。如果模組沒有開啟工作流,就直接放行。如果開啟了工作流,就啟動該模組的工作流流程。下面上 target elementtype.method retention retentionp...

自定義註解搭配AOP使用

首先敘述一下業務,在每個模組中達到某要求時都要給當前使用者新增積分,所以這裡用到了註解搭配aop。首先自定義乙個註解 author zhanggx date 2021 01 06 16 40 target retention retentionpolicy.runtime documented pu...