一: 通過AopContext獲取代理類對象
springboot中如何配置aop動態代理模式
=============================
第一種方式:
在application.yml中有以下配置
spring:
aop:
#auto: true #默認為true,可省略
proxy-target-class: true # 默認為false即JDK動態代理,我們一般要設為true,使用CGLIB代理
這種方式只能將代理模式修改為了CGLIG,但是不能設置暴露cglib代理的目標對象。
========================================
第二種方式:
在springboot啟動類上標記這個注解
@EnableAspectJAutoProxy(exposeProxy=true,proxyTargetClass=true)
同時,排除 AopAutoConfiguration.class的自動化配置
很好,這種方式同時設置exposeProxy為true和proxyTargetClass為true,即強制采用cglib代理,和暴露cglib代理的目標對象。
====================================
第三種方式:
在springboot啟動類上引入spring.xml配置文件
@ImportResource({"classpath:/spring.xml"})
同時,排除 AopAutoConfiguration.class的自動化配置
在spring.xml 配置文件中配置
<!--1 aspectj 切面的支持 ,強制使用cglib,並暴露cglib代理的目標對象-->
<aop:aspectj-autoproxy proxy-target-class="true" expose-proxy="true"/>
<context:annotation-config />
