大战熟女丰满人妻av-荡女精品导航-岛国aaaa级午夜福利片-岛国av动作片在线观看-岛国av无码免费无禁网站-岛国大片激情做爰视频

專(zhuān)注Java教育14年 全國(guó)咨詢(xún)/投訴熱線(xiàn):400-8080-105
動(dòng)力節(jié)點(diǎn)LOGO圖
始于2009,口口相傳的Java黃埔軍校
首頁(yè) hot資訊 三種AOP的實(shí)現(xiàn)方式

三種AOP的實(shí)現(xiàn)方式

更新時(shí)間:2022-10-26 09:33:13 來(lái)源:動(dòng)力節(jié)點(diǎn) 瀏覽1994次

AOP的實(shí)現(xiàn)方式有三種:

1.使用Spring的API接口(主要是SpringAPI接口實(shí)現(xiàn))

2.自定義實(shí)現(xiàn)AOP(主要是切面定義,自定義類(lèi))

3.使用注解實(shí)現(xiàn)

<?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:p="http://www.springframework.org/schema/p"
       xmlns:c="http://www.springframework.org/schema/c"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       https://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/aop
       https://www.springframework.org/schema/aop/spring-aop.xsd">
    <!--    <bean id="user" class="com.bing.pojo.User" p:name="cb" p:age="23"></bean>-->
<!--注冊(cè)成bean-->
    <bean id="UserService" class="com.bing.service.UserServiceImpl"></bean>
    <bean id="log" class="com.bing.log.Log"></bean>
    <bean id="afterlog" class="com.bing.log.AfterLog"></bean>
<!--&lt;!&ndash;    方式一:使用原生spring API接口&ndash;&gt;-->
<!--&lt;!&ndash;    配置aop&ndash;&gt;-->
<!--    <aop:config>-->
<!--&lt;!&ndash;        需要一個(gè)切入點(diǎn),即我們需要在哪個(gè)地方執(zhí)行方法 exe: 返回值 類(lèi)名 方法名 參數(shù)&ndash;&gt;-->
<!--        <aop:pointcut id="pointcut" expression="execution(* com.bing.service.UserServiceImpl.*(..))"/>-->
<!--        &lt;!&ndash;    執(zhí)行環(huán)繞增加&ndash;&gt;-->
<!--&lt;!&ndash;把log類(lèi)切入到pointcut方法上面&ndash;&gt;-->
<!--        <aop:advisor advice-ref="log" pointcut-ref="pointcut"></aop:advisor>-->
<!--        <aop:advisor advice-ref="afterlog" pointcut-ref="pointcut"></aop:advisor>-->
<!--    </aop:config>-->
<!--    方式二 自定義類(lèi) 用切面,是一個(gè)類(lèi)-->
<!--    <bean id="diy" class="com.bing.diy.DiyPointCut"/>-->
<!--         <aop:config>-->
<!--&lt;!&ndash;             自定義切面, 引入diy類(lèi)&ndash;&gt;-->
<!--              <aop:aspect ref="diy" >-->
<!--                  <aop:pointcut id="point" expression="execution(* com.bing.service.UserServiceImpl.*(..))"/>-->
<!--                  &lt;!&ndash;有切面類(lèi)就有通知了,就是有方法了&ndash;&gt;-->
<!--                  <aop:before method="before" pointcut-ref="point"/>-->
<!--                  <aop:after method="after" pointcut-ref="point"/>-->
<!--              </aop:aspect>-->
<!--         </aop:config>-->
<!--    方式三-->
    <bean id="annotationPointCut" class="com.bing.diy.AnnotationPointCut"></bean>
<!--    開(kāi)啟注解支持 自動(dòng)代理-->
    <aop:aspectj-autoproxy></aop:aspectj-autoproxy>
</beans>
//方法一、二
package com.bing.diy;
public class DiyPointCut {
    public void before(){
        System.out.println("執(zhí)行前");
    }
    public void after(){
        System.out.println("執(zhí)行后");
    }
}
//方法三(注解)
package com.bing.diy;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
//使用注解直接將其類(lèi)標(biāo)記成切面
@Aspect
public class AnnotationPointCut {
//Before里面寫(xiě)切入點(diǎn)
    @Before("execution(* com.bing.service.UserServiceImpl.*(..))")
    public void before(){
        System.out.println("方法執(zhí)行前");
    }
    @After("execution(* com.bing.service.UserServiceImpl.*(..))")
    public void after(){
        System.out.println("方法執(zhí)行后");
    }
    //在環(huán)繞增強(qiáng)中,我們可以給定一個(gè)參數(shù),代表我們要處理切入的點(diǎn)
    @Around("execution(* com.bing.service.UserServiceImpl.*(..))")
    public void around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        System.out.println("環(huán)繞前");
        //執(zhí)行方法,過(guò)濾
        Object proceed = proceedingJoinPoint.proceed();
        System.out.println("環(huán)繞后 ");
    }
}

 

提交申請(qǐng)后,顧問(wèn)老師會(huì)電話(huà)與您溝通安排學(xué)習(xí)

免費(fèi)課程推薦 >>
技術(shù)文檔推薦 >>
主站蜘蛛池模板: 亚洲免费视频在线观看 | 看特级大黄一片 | 国产a做爰全过程片 | 色爱区综合激情五月综合色 | 亚洲国产欧美在线不卡中文 | 操熟美女又肥又嫩的骚屁股 | 亚洲综合中文网 | 999国内精品永久免费视频 | 青青青国产在线 | 日本a视频 | 国产精品免费精品自在线观看 | 亚洲在线视频免费 | 亚洲aa视频 | 国产精品精品 | 中文字幕在线观看日本 | 亚洲色视频在线播放网站 | 久久在线观看免费视频 | 欧美日韩国产成人综合在线影院 | 欧美理论片大全在线观看 | 欧美a一片xxxx片 | 97视频在线观看视频最新 | 人人澡人人人人夜夜爽 | 999热精品这里在线观看 | 成年女人视频免费免费看 | 久久青草免费91线频观看不卡 | 能在线观看的一区二区三区 | 欧美一二区 | 青青青爽视频在线观看入口 | 深夜福利免费观看 | 四虎影院网站 | 性大特级毛片视频 | 国产精品福利午夜h视频 | 欧美一级毛片不卡免费观看 | 国产91在线精品福利 | 在线视频 亚洲 | 一级毛片免费不卡在线 | 夜夜爽夜夜| 久久国产欧美 | 欧美三级一区二区 | 一级毛片在线免费观看 | 欧美午夜在线 |