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:表示在核心类的方法完成后在进行增强