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

專注Java教育14年 全國咨詢/投訴熱線:400-8080-105
動力節點LOGO圖
始于2009,口口相傳的Java黃埔軍校
首頁 hot資訊 三種AOP的實現方式

三種AOP的實現方式

更新時間:2022-10-26 09:33:13 來源:動力節點 瀏覽1714次

AOP的實現方式有三種:

1.使用Spring的API接口(主要是SpringAPI接口實現)

2.自定義實現AOP(主要是切面定義,自定義類)

3.使用注解實現

<?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>-->
<!--注冊成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;        需要一個切入點,即我們需要在哪個地方執行方法 exe: 返回值 類名 方法名 參數&ndash;&gt;-->
<!--        <aop:pointcut id="pointcut" expression="execution(* com.bing.service.UserServiceImpl.*(..))"/>-->
<!--        &lt;!&ndash;    執行環繞增加&ndash;&gt;-->
<!--&lt;!&ndash;把log類切入到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>-->
<!--    方式二 自定義類 用切面,是一個類-->
<!--    <bean id="diy" class="com.bing.diy.DiyPointCut"/>-->
<!--         <aop:config>-->
<!--&lt;!&ndash;             自定義切面, 引入diy類&ndash;&gt;-->
<!--              <aop:aspect ref="diy" >-->
<!--                  <aop:pointcut id="point" expression="execution(* com.bing.service.UserServiceImpl.*(..))"/>-->
<!--                  &lt;!&ndash;有切面類就有通知了,就是有方法了&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>
<!--    開啟注解支持 自動代理-->
    <aop:aspectj-autoproxy></aop:aspectj-autoproxy>
</beans>
//方法一、二
package com.bing.diy;
public class DiyPointCut {
    public void before(){
        System.out.println("執行前");
    }
    public void after(){
        System.out.println("執行后");
    }
}
//方法三(注解)
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;
//使用注解直接將其類標記成切面
@Aspect
public class AnnotationPointCut {
//Before里面寫切入點
    @Before("execution(* com.bing.service.UserServiceImpl.*(..))")
    public void before(){
        System.out.println("方法執行前");
    }
    @After("execution(* com.bing.service.UserServiceImpl.*(..))")
    public void after(){
        System.out.println("方法執行后");
    }
    //在環繞增強中,我們可以給定一個參數,代表我們要處理切入的點
    @Around("execution(* com.bing.service.UserServiceImpl.*(..))")
    public void around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        System.out.println("環繞前");
        //執行方法,過濾
        Object proceed = proceedingJoinPoint.proceed();
        System.out.println("環繞后 ");
    }
}

 

提交申請后,顧問老師會電話與您溝通安排學習

免費課程推薦 >>
技術文檔推薦 >>
主站蜘蛛池模板: 国产一级视频播放 | 日本免费小视频 | 国产免费一区二区三区在线 | 四虎成人影视 | 久久美女 | 国产精品成人久久久久久久 | 毛片真人毛毛片毛片 | 久久综合亚洲一区二区三区 | 深夜影院老司机69影院 | 国产精品视频免费视频 | 99免费在线观看 | 中国性猛交xxxxx免费看 | 婷婷综合五月 | 在线欧美精品一区二区三区 | 91精品视频在线免费观看 | 俄罗斯老妇性欧美毛茸茸孕交 | 亚洲永久精品ww47 | 中国美女一级a毛片录像在线 | 国产日韩欧美精品一区 | 日本在线观看中文字幕 | 欧美日韩国产一区二区三区播放 | 狠狠色丁香久久婷婷综合丁香 | 色久天堂网| 成 人 黄 色 | 中文日韩| 精品欧美一区二区在线看片 | 一本久道久久综合狠狠爱 | 中文字幕亚洲一区二区三区 | 日本一级高清片免费 | 在线国产一区 | 九九热播视频 | 国产羞羞羞视频在线观看 | 亚洲综合色婷婷久久 | chinese456老人gay| 久久婷婷色 | 在线亚洲欧美日韩 | 狠狠综合久久综合网站 | 一区亚洲 | 日韩一区国产二区欧美三 | 99视频在线观看视频一区 | 亚洲在线一区 |