閱讀目錄
- 既可以在目標方法之前織入增強動作,也可以在執行目標方法之后織入增強動作;
- 它可以決定目標方法在什么時候執行,如何執行,甚至可以完全阻止目標目標方法的執行;
- 它可以改變執行目標方法的參數值,也可以改變執行目標方法之后的返回值;
- 當需要改變目標方法的返回值時,只能使用Around方法;
雖然Around功能強大,但通常需要在線程安全的環境下使用。因此,如果使用普通的Before、AfterReturing增強方法就可以解決的事情,就沒有必要使用Around增強處理了。
二、定義切面類、連接點注解類

PointCut連接點注解類

說明:
這是一個注解類型:
@interface
類中設置了一個methodName屬性;
定義切面類

說明:
- @Around定義了此方法為 Around增強處理方法;
- @annotation(around):參數around應該與增強處理方法中的參數名保持一致,該聲明指定了pointcut連接點,也可以使用其他方式,如:
pointcut="execution(* org.crazyit.app.service.impl.*.*(..))";
- point.proceed()調用了目標方法,並獲取其返回值;
三、為待增強的方法--添加注解聲明
在上面定義@Around增強時,通過
@annotation() 方式指定了pointcut,其中方法參數為連接點注解類
aroundAuthority,

如果需要對某一方法進行增強,只需要在相應的方法上添加上此注解即可,如下:


四、AspectJ配置文件


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task" xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
<!-- 啟動@AspectJ支持 -->
<aop:aspectj-autoproxy />
<context:component-scan base-package="com.sssppp.Spring.aop">
</context:component-scan>
</beans>



《@AfterReturning增強處理簡單示例》
http://www.cnblogs.com/ssslinppp/p/4633496.html
《@After后向增強處理簡單示例》
http://www.cnblogs.com/ssslinppp/p/4633427.html
《@Before前向增強處理簡單示例》
http://www.cnblogs.com/ssslinppp/default.html?page=7