創新互聯www.cdcxhl.cn八線動態BGP香港云服務器提供商,新人活動買多久送多久,劃算不套路!
AOP核心概念
1、橫切關注點
對哪些方法進行攔截,攔截后怎么處理,這些關注點稱之為橫切關注點
2、切面(aspect)
類是對物體特征的抽象,切面就是對橫切關注點的抽象
3、連接點(joinpoint)
被攔截到的點,因為spring只支持方法類型的連接點,所以在Spring中連接點指的就是被攔截到的方法,實際上連接點還可以是字段或者構造器
4、切入點(pointcut)
對連接點進行攔截的定義
5、通知(advice)
所謂通知指的就是指攔截到連接點之后要執行的代碼,通知分為前置、后置、異常、最終、環繞通知五類
6、目標對象
代理的目標對象
7、織入(weave)
將切面應用到目標對象并導致代理對象創建的過程
8、引入(introduction)
在不修改代碼的前提下,引入可以在運行期為類動態地添加一些方法或字段
Spring 實現AOP所需要的包:
1、Spring提供的jar包
2、aopalliance.jar
3、aspectjweaver.jar
Spring 實現AOP的方式:
1、Java動態代理
該方法針對接口的實例創建代理
applicationContext.xml的配置如下:
<?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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd"> <bean id="concreteImplementor" class="com.marving.aop.ConcreteImplementor" /> <bean id="interceptorHandler" class="com.marving.aop.InterceptorHandler" /> <aop:config> <aop:aspect id="interceptor" ref="interceptorHandler"> <aop:pointcut id="addAllMethod" expression="execution(* com.marving.aop.Abstration.*(..))" /> <aop:before method="doSomething" pointcut-ref="addAllMethod" /> <aop:after method="doSomething" pointcut-ref="addAllMethod" /> </aop:aspect> </aop:config> </beans>
文章標題:SpringAOP的幾種實現方式總結-創新互聯
標題鏈接:http://vcdvsql.cn/article40/pjseo.html
成都網站建設公司_創新互聯,為您提供微信小程序、品牌網站建設、網站制作、自適應網站、服務器托管、網站設計公司
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯