-
方式一 :使用Spring的API接口【主要使用SpringAPI 接口实现的,也就是动态代理】
-
方式二:自定义类实现AOP 【主要是切面定义】
-
方式三:使用注解的方式实现
<?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: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/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
<!--注册SpringBean -->
<bean id="UserSercice" class="com.ZQQQ.service.UserServiceimpl"/>
<bean id="log" class="com.ZQQQ.log.log"/>
<bean id="Afterlog" class="com.ZQQQ.log.Afterlog"/>
<!-- 方式一 spring 原生>
<!- - 配置Aop :需要导入aop的约束-->
<Aop:config>
<!--切入点 -->
<Aop:pointcut id="pointcut" expression="execution(* com.ZQQQ.service.UserServiceimpl.*(..))"/>
<!--执行环绕增加 -->
<Aop:advisor advice-ref="log" pointcut-ref="pointcut"/>
<Aop:advisor advice-ref="Afterlog" pointcut-ref="pointcut"/>
</Aop:config>
<!--方式二 自定义类 -->
<bean id="diy" class="com.ZQQQ.diy.DiypointCut"/>
<Aop:config>
<!-- 自定义切面ref要引用的类-->
<Aop:aspect ref="diy">
<!--切入点 -->
<Aop:pointcut id="point" expression="execution(* com.ZQQQ.service.UserServiceimpl.*(..))"/>
<!-- 通知-->
<Aop:before method="before" pointcut-ref="point"/>
<Aop:after method="after" pointcut-ref="point"/>
</Aop:aspect>
</Aop:config>
<!--方式三 -->
<bean id="diy" class="com.ZQQQ.diy.AnnotationPointCut"/>
<!-- 开启注解支持! proxy-target-class="false" proxy-target-class="true"-->
<Aop:aspectj-autoproxy/>
</beans>
- JDk (默认 proxy-target-class=“false” )
- proxy-target-class=“true” 设置为true时是 使用动态代理的cglib实现的