日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

Spring-AOP 引介切面

發布時間:2025/3/21 javascript 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Spring-AOP 引介切面 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

  • 概述
    • 引介切面類繼承關系
    • IntroductionAdvisor接口的兩個實現類
    • DefaultIntroductionAdvisor的構造函數
  • 實例

概述

之前的博文介紹了 Spring-AOP 通過配置文件實現 引介增強 ,引介切面是引介增強的封裝器,通過引介切面可以很容易的為現有對象添加任何接口的實現。

引介切面類繼承關系

IntroductionAdvisor 和 PointcutAdvisor不同,IntroductionAdvisor 僅有一個類過濾器ClassFilter而沒有MethodMatcher,因為引介切面是類級別的,而Poincut的切點是方法級別的。

IntroductionAdvisor接口的兩個實現類

  • DefaultIntroductionAdvisor
    引介切面最常用的實現類

  • DeclareParentsAdvisor
    用于實現使用AspectJ語言的DeclareParent注解表示的引介切面。

DefaultIntroductionAdvisor的構造函數

  • public DefaultIntroductionAdvisor(Advice advice)

    通過一個增強創建的引介切面,引介切面將為目標對象增強對象中所有接口的實現

  • public DefaultIntroductionAdvisor(Advice advice, IntroductionInfo
    introductionInfo)
    通過一個增強和一個IntroductionInfo創建引介切面,目標對象小實現哪些接口由introduction對象的getInterfaces()方法標識

  • public DefaultIntroductionAdvisor(DynamicIntroductionAdvice advice,
    Class<?> intf)
    通過一個IE增強和一個指定的接口類創建引介切面,僅為目標對象新增intf接口的實現


實例

代碼已托管到Github—> https://github.com/yangshangwei/SpringMaster

其余代碼同 Spring-AOP 通過配置文件實現 引介增強

我們通過DefaultIntroductionAdvisor配置引介切面,更加簡潔、清晰

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"><!-- 目標類 --><bean id="forumServiceTarget" class="com.xgj.aop.spring.advisor.introductionAdvisor.ForumService" /><!-- 切面 --><bean id="introductionAdvisor" class="org.springframework.aop.support.DefaultIntroductionAdvisor"><constructor-arg><bean class="com.xgj.aop.spring.advisor.introductionAdvisor.ControllablePerformaceMonitor"/></constructor-arg></bean><!-- 代理類 --><bean id="forumService" class="org.springframework.aop.framework.ProxyFactoryBean"p:interceptorNames="introductionAdvisor"p:target-ref="forumServiceTarget" p:proxyTargetClass="true" /></beans>

運行結果:

2017-08-20 19:02:30,492 INFO [main] (AbstractApplicationContext.java:583) - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@5f0101fb: startup date [Sun Aug 20 19:02:30 BOT 2017]; root of context hierarchy 2017-08-20 19:02:30,598 INFO [main] (XmlBeanDefinitionReader.java:317) - Loading XML bean definitions from class path resource [com/xgj/aop/spring/advisor/introductionAdvisor/conf-introductionAdvisor.xml] 模擬刪除Forum記錄:10 模擬刪除Topic記錄:1022 begin monitor... 模擬刪除Forum記錄:10 end monitor... org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.removeForum花費7421毫秒。 begin monitor... 模擬刪除Topic記錄:1022 end monitor... org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.removeTopic花費12468毫秒。

雖然引介切面和其他切面的配置有很大的不同,但卻可以采用相似的Spring配置方式配置引介切面。

總結

以上是生活随笔為你收集整理的Spring-AOP 引介切面的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。