Aop简介

什么是Aop?

它的作用和优势?

Aop的动态代理技术:

概念相关:

开发相关:

开发步骤

xml实现:

        1、导入 AOP 相关坐标;
        2、创建目标接口和目标类(内部有切点);
        3、创建切面类(内部有增强方法);
        4、将目标类和切面类的对象创建权交给 spring;
        5、在 applicationContext.xml 中配置织入关系;
        6、测试代码。

<!-- 目标对象 -->
    <bean id="target" class="xml实现.Target.Target"></bean>

    <!-- 切面对象 -->
    <bean id="myAspect" class="xml实现.Aspect.myAspect"></bean>

    <!-- 配置织入:告诉spring框架哪些方法需要进行哪些增强 -->
    <aop:config>
        <!--声明切面-->
        <aop:aspect ref="myAspect">
            <!--声明切点和增强-->
            <aop:before method="before" pointcut="execution(public void xml实现.Target.Target.run())"/>
            <aop:after-returning method="afterReturning" pointcut="execution(void xml实现.Target.Target.run()))"/>
            <aop:around method="around" pointcut="execution(void xml实现.Target.Target.run()))"/>
            <aop:after-throwing method="afterThrowing" pointcut="execution(* xml实现.Target.Target.run())"/>
            <aop:after method="after" pointcut="execution(* xml实现.Target.Target.run())"/>

            <!--抽取切点表达式-->
            <aop:pointcut id="myPointcut" expression="execution(* xml实现.Target.Target.run())"></aop:pointcut>
            <aop:before method="before" pointcut-ref="myPointcut"/>
        </aop:aspect>
    </aop:config>

注解实现:

        1、导入 AOP 相关坐标;
        2、创建目标接口和目标类(内部有切点);
        3、创建切面类(内部有增强方法);
        4、在切面类中使用注解配置织入关系;
        5、在 applicationContext.xml 中开启组件扫描和Aop自动代理;

    <!-- aop自动代理 -->
    <aop:aspectj-autoproxy/>


        6、测试代码。

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值