exposeProxy((Pojo) AopContext.currentProxy()).bar();如果调用了AopContext.currentProxy,需要把exposeProxy设置true,否则会报下面错误:Exception in thread "main" java.lang.IllegalStateException: Cannot find current proxy: Set 'exposeProxy' property on Advised to 'true' to
原创 2021-08-25 09:24:40
2327阅读
exposeProxy((Pojo) AopContext.currentProxy()).bar();如果调用了AopContext.currentProxy,需要把exposeProxy设置true
原创 2022-02-18 09:52:56
1217阅读
出现这个报错通常是因为使用了AopContext.currentProxy()函数却没有添加相应的配置造成的。 通过注解添加配置(加在类上): @EnableAspectJAutoProxy(proxyTargetClass = true, exposeProxy = true) 或通过xml配置文
转载 2020-07-07 07:29:00
7226阅读
2评论
前言本文标题包含有​​'靓丽'​​的字眼:​​Spring框架bug​​。相信有的小伙伴心里小九九就会说了:又是一篇标题党文章。 鉴于此,此处可以很负责任的对大伙说:本人所有文章绝不​​哗众取宠​​,除了干货只剩干货。相信关注过我的小伙伴都是知道的,我只递送干货,绝不标题党来浪费大家的时间和精力~那无异于​​谋财害命​​(说得严重了,不喜勿喷) 关于标题党的好与坏、优与劣,此处我不置可否本篇文章能
转载 2020-04-01 00:00:00
121阅读
相关博文【小家java】POP(面向过程编程)、OOP(面向对象编程)、AOP(面向切面编程)三种编程思想的区别和联系【小家Spring】Spring AOP的多种使用方式以及神一样的AspectJ-AOP使用介绍【小家Spring】Spring AOP中@Pointcut切入点表达式最全面使用介绍前言一说到Spring AOP肯定很多人特别的熟悉,也许在自己的项目中都有使用到。若想对编...
原创 2021-07-18 15:45:58
1406阅读
前言从本文标题就能
原创 2021-07-18 22:52:02
1153阅读
1点赞
文章目录1 先看现象2 从源码看一下exposeProxy在事务源码中的逻辑3 解决方式源码地址:https://github.com/nieandsun/spring-study1 先看现象有如下代码,调用addUserAndSalary方法,t_user表和t_salary表哪个表里会被插入数据呢???@Servicepublic class UserServiceImpl i...
proxyTargetClass=true:强制使用cglib动态代理。可以通过AopProxy.currentProxy来拿到代理对象。exposeProxy=true在当前线程暴露代理对象。
原创 2023-10-18 11:50:32
101阅读
本文主要来自org.springframework.aop.framework当前包的相关类ProxyConfigprivate boolean proxyTargetClass = false;private boolean optimize = false;boolean opaque = false;boolean exposeProxy = false;private boolean frozen = false;public void copyFrom(ProxyConfi
原创 2021-08-25 09:24:44
223阅读
使用AopContxt.currentProxy()方法可获取当前类的代理对象(是通过StaticUnadvisedExposedInterceptor或DynamicUnadvisedExposedInterceptor或JdkDynamicAopProxy#invoke中设置的,@EnableAspectJAutoProxy#exposeProxy可设置为true,将当前的aop对象暴露到Ao
转载 10月前
10阅读
前言上篇博文:【小家Spring】面向切面编程之—Spring AOP的原理讲解以及源码分析(Cannot find current proxy: Set ‘exposeProxy’ property on )已经刚刚结合实例,介绍了Spring AOP的过程原理以及对源码进行了逐步分析~但是这中间当时事忽略了整个Spring AOP最为核心的一个类:自动代理创建器。因此本文将以Annot...
原创 2021-07-18 22:44:15
368阅读
目录一、本类嵌套Aop问题分析二、本类嵌套Aop问题解决1、依赖注入自己2、BeanFactoryAware(或者ApplicationContextAware)3、exposeProxy设置为true    之前分析了整个Aop的实现原理和流程。Spring框架的Transactional,Async等都是基于Spring Aop进行实现的。那么很多时候我们在同一个Bean中
Spring嵌套事物的执行过程异常(UnexpectedRollbackException)的分析,需要注意一下两点:这里不是指传播性Propagation.NESTED嵌套事物,而是指方法间调用嵌套不同传播性事物Spring AOP一个类方法之间的调用不会走代理类,可以通过以下两种方式可以获取到当前代理对象@EnableAspectProxy#exposeProxy()为truexml配置通过以
Spring AOP 自调用方法处理使用过Spring aop的基本都知道代理模式下自调用时Advice不生效。Spring 官网给的方案是暴露代理(exposeProxy=true) 使用ThreadLocal 来传递代理对象操作。AopContext.currentProxy()然而这样是又违背了AOP的设计理念,这样做代码耦合,而且Spring官网也提出来一下一段话来自官网。// this