AOP中定義切點

2021-09-27 11:57:21 字數 1416 閱讀 5029

一 配置

<?xml version="1.0" encoding="gbk"?>

二 切面類

systemarchitecture

import org.aspectj.lang.annotation.*;

@aspect

public class systemarchitecture}

logaspect

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)

return 20;

}} 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

模擬記錄日誌功能...

Spring框架 AOP中切點採用aspectj

1 框架 execution 切點語言表示式 2 表示式格式 返回型別 包名.子包名.類名.方法名 引數型別列表 3 號是包名之間 或 包名與類名之間 或 類名與方法名 之間的間隔符 4 在包路徑位置代表的是任意深的目錄,在引數型別列表中代表的是任意個數與型別的引數 5 號 是作業系統中的萬用字元 ...

Spring 2 0及以上AOP 切點配置整理

常見的情況 示例1 com.accp.service.service.com.accp.service 包 com.accp.service com.accp.service.包 com.accp.service 及其子包,比如 com.accp.service.abc com.accp.servi...

AOP定義AfterReturning增加實戰

一 配置 二 切面類 import org.aspectj.lang.annotation.import org.aspectj.lang.定義乙個切面 aspect public class logaspect 三 介面 hello public inte ce hello world publi...