一 配置
<?xml version="1.0" encoding="gbk"?>
二 切面類
import org.aspectj.lang.annotation.*;
import org.aspectj.lang.*;
// 定義乙個切面
@aspect
public class logaspect}
三 介面
hello
public inte***ce hello
world
public inte***ce world
四 實現類
helloimpl
import org.springframework.stereotype.component;
@component("hello")
public class helloimpl implements hello
// 定義乙個adduser()方法,模擬應用中的新增使用者的方法
public int adduser(string name, string pass) }
worldimpl
import org.springframework.stereotype.component;
@component("world")
public class worldimpl implements world }
五 測試類
package lee;
import org.springframework.context.*;
import org.springframework.context.support.*;
public class beantest
}
六 測試結果
執行hello元件的foo()方法
獲取目標方法返回值:null
模擬記錄日誌功能...
執行hello元件的adduser新增使用者:孫悟空
獲取目標方法返回值:20
模擬記錄日誌功能...
執行world元件的bar()方法
獲取目標方法返回值:null
模擬記錄日誌功能...
AOP中定義切點
一 配置 二 切面類 systemarchitecture import org.aspectj.lang.annotation.aspect public class systemarchitecture logaspect import org.aspectj.lang.annotation.i...
AOP 自定義註解
compile org.springframework.boot spring boot starter aop aspect component public class auditaspect before weblog public void debefore joinpoint joinpo...
AOP定義Before增加實戰
一 配置 二 切面類 import org.aspectj.lang.annotation.import org.aspectj.lang.定義乙個切面 aspect public class authaspect 三 介面 hello public inte ce hello world publ...