久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

java - spring AOP 不生效

瀏覽:107日期:2024-01-28 14:58:30

問題描述

寫了個切面, 如果切點定義聲明在Controller上面的方法,這對應的通知能夠執行, 如果不是Controller直接調用的則通知無法執行.

切面聲明:

@Aspect@Componentpublic class SessionAspect { @Pointcut('execution(* cn.test.service.impl.ShopServiceImpl.myShops(..))') private void myShops() { }@Pointcut('execution(* cn.test.service.impl.ShopServiceImpl.test(..))') private void test() { } @Before('myShops()') public void doBefore() {System.out.println('hello'); }@Before('test()') public void doBefore() {System.out.println('test'); }}

controller 的方法

@RequestMapping(value = '/my', method = RequestMethod.GET)public Object myShops(String userSid, ModelMap result) { return this.shopService.myShops(userSid);}

因為myShops在controller中直接調用, 通知能夠觸發執行, 打印出hello, 而test方法沒有在controller中顯示調用, 所有即便執行了test方法也不會通知也沒有被觸發執行.基于Spring MVC.

問題解答

回答1:

Spring AOP 只對 Bean 進行代理,如果你的實例不是從 Spring 獲取來的 Bean 而是自己實例出來的它是沒法進行代理的。

標簽: java
相關文章:
主站蜘蛛池模板: 青岛市| 海原县| 邵阳县| 林西县| 萨迦县| 岑溪市| 遂平县| 厦门市| 莲花县| 六盘水市| 姚安县| 海盐县| 云林县| 南召县| 高碑店市| 通城县| 布尔津县| 哈尔滨市| 扎囊县| 温泉县| 罗源县| 德清县| 平顶山市| 吴川市| 迭部县| 大化| 台湾省| 西乌| 田阳县| 康定县| 绵竹市| 原阳县| 周宁县| 屏南县| 平乡县| 渝中区| 永福县| 皮山县| 安陆市| 区。| 远安县|