要點:
1.aop的概念真的很多。。。其實從使用出發無非兩點:1,定義要攔截的方法,2,實現攔截後的操作方法。
2.基於註解的@aspect需要配合bean宣告來用,不然不報錯,不執行。。官方doc貌似沒提倒。
3. 注入的bean物件,訪問其屬性需要生成get/set方法, 如果直接訪問也會出現空指標。
@autowired private memcacheservice memcacheservice;
//報空指標
memcacheservice.memcachedclient.set();
//下面方法ok
memcacheservice.getmemcachedclient().set()
4.極有可能導致基於註解的bean巢狀bean產生nullpointerexception
@component
@aspect
具體做法示例**如下:1.execution**指定攔截service包,2.@
@around說明在方法前後攔截。 詳細說明可以參考附錄文件
@component
@aspect
public class serviceadvice
}
基於spring 3 註解的junit測試
import org.junit.test import org.junit.runner.runwith import org.springframework.beans.factory.annotation.autowired import org.springframework.test.co...
基於spring 3 註解的junit測試
importorg.junit.test importorg.junit.runner.runwith importorg.springframework.beans.factory.annotation.autowired importorg.springframework.test.contex...
常用spring3註解
configuration把乙個類作為乙個ioc容器,它的某個方法頭上如果註冊了 bean,就會作為這個spring容器中的bean。scope註解 作用域 lazy true 表示延遲初始化 service用於標註業務層元件 controller用於標註控制層元件 如struts中的action ...