Spring ---->AOP 三种切面编程的配置方式( 九 )

  • 方式一 :使用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实现的
    在这里插入图片描述
案例:详见上一章节
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值