springboot 使用CGLib 方式实现AOP代理

来源:互联网 发布:图片动态特效制作软件 编辑:程序博客网 时间:2024/05/29 14:58

前言:

Spring boot 和使用Spring 完全是两个不同的样子,一个是前者是基于编程式,后者是基于XML配置。


一、如何使用CGLIB动态代理

spring 的动态代理默认是jdk的动态代理,需要在application.properties或者application.yml去设置如下属性:

application.properties:

spring.aop.proxy-target-class

传统Spring配置文件

XML

<aop:aspectj-autoproxy proxy-target-class="true" expose-proxy="true"/>
expose-proxy="true"   #是暴露当前代理状态,在使用AopContext.CurrentProxy();的时候配合使用

二、添加jar依赖
dependency>      <groupId>org.springframework.boot</groupId>      <artifactId>spring-boot-starter-aop</artifactId>  </dependency>  
版本号根据parent即可

<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.5.6.RELEASE</version><relativePath/> <!-- lookup parent from repository --></parent>



原创粉丝点击