动态代理和增强类

1.什么是动态代理

动态代理就是创建的代理对象,在代码运行期间,创建的代理对象称之为动态代理

 如何创建代理对象

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd
       http://www.springframework.org/schema/aop
       http://www.springframework.org/schema/aop/spring-aop.xsd">
    <!-- 1.把所有类的对象交给IOC容器进行管理 -->
    <!-- 2.AOP的配置:让增强类 的 哪个方法  动态进行何种增强   核心类 的 哪个方法 -->
    <bean id="loger" class="com.qi.advice.Loger"/>
    <bean id="bookService" class="com.qi.service.impl.BookServiceImpl"/>

    <!--2.AOP配置-->
    <aop:config>
        <!--配置 增强类的哪个方法    对    核心类的哪个方法    进行    何种增强-->
        <aop:aspect id="log" ref="loger">
            <aop:before method="check" pointcut="execution(* *..BookServiceImpl.*(..))"/>
            <aop:after-returning method="check" pointcut="execution(* *..BookServiceImpl.*(..))"/>
            <aop:after-throwing method="check" pointcut="execution(* *..BookServiceImpl.*(..))"/>
            <aop:after method="check" pointcut="execution(* *..BookServiceImpl.*(..))"/>
        </aop:aspect>
    </aop:config>
</beans>

2.如何增强类

增强类就是aop配置里增强类(loger)的哪个方法 对 核心类的(BookServiceImpl)哪个方法 进行何种增强

*表示所有 

before:表示增强之前就要进行验证

after-returning:表示在return之后在进行增强

after-throwing:处理一些异常

after:表示在核心类的方法完成后在进行增强

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值