spring boot 代理(not eligible for auto-proxying)

本文探讨了Spring框架中事务管理的常见问题,包括事务无法回滚的原因及解决策略,以及如何处理某些Service未生成代理类导致的事务管理失效问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题一:
    在同一个对象中有两个方法,分别未方法A,方法B(添加了事务),在方法A中调用方法B,出现了事务不能回滚的情况:

/**
* 方法A
*/
public void methodA(){
System.out.println("I an methodA ...");
}
/**
* 方法B
*/
@Transactional
public void methodB(){
System.out.println("I an methodB ...");
//手动回滚事务
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
}


此时报异常

org.springframework.transaction.NoTransactionException: No transaction aspect-managed TransactionStatus in scope
解决方案:新建一个类,将方法B放在新建的类中,定义格式不变,然后在原来的类中调用即可,这是因为spring的事务依赖的是AOP,spring在初始化bean 是生成了一个代理类,在第一个方法中有代理类的存在,调用本类其他方法是是使用的对象本身而不是代理类,故而事务不能回滚。

问题二:
    springboot项目中不知因为什么原因有些service未生成代理类,在启动时:

is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying
虽然此条日志信息时info级别的不影响正常的运行。可是出现此问题的类中service 就是不回滚,不知道此问题的原因,有知道的烦请告知一二,万分感谢。

解决方案:在此类中添加注解  

@Scope(proxyMode = ScopedProxyMode.INTERFACES)
此注解意思是生成一个jdk代理类,从而解决此问题

转载于:https://www.cnblogs.com/matd/p/11127500.html

2025-03-28 18:40:37 WARN 47864 --- [GraduateProject-projectService] [ main] trationDelegate$BeanPostProcessorChecker : Bean 'io.seata.spring.boot.autoconfigure.SeataCoreAutoConfiguration' of type [io.seata.spring.boot.autoconfigure.SeataCoreAutoConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying). Is this bean getting eagerly injected/applied to a currently created BeanPostProcessor []? Check the corresponding BeanPostProcessor declaration and its dependencies/advisors. If this bean does not have to be post-processed, declare it with ROLE_INFRASTRUCTURE. 2025-03-28 18:40:37 WARN 47864 --- [GraduateProject-projectService] [ main] trationDelegate$BeanPostProcessorChecker : Bean 'springApplicationContextProvider' of type [io.seata.spring.boot.autoconfigure.provider.SpringApplicationContextProvider] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying). Is this bean getting eagerly injected/applied to a currently created BeanPostProcessor []? Check the corresponding BeanPostProcessor declaration and its dependencies/advisors. If this bean does not have to be post-processed, declare it with ROLE_INFRASTRUCTURE. 2025-03-28 18:40:37 WARN 47864 --- [GraduateProject-projectService] [ main] trationDelegate$BeanPostProcessorChecker : Bean 'io.seata.spring.boot.autoconfigure.SeataAutoConfiguration' of type [io.seata.spring.boot.autoconfigure.SeataAutoConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying). Is this bean getting eagerly injected/applied to a currently created BeanPostProcessor []? Check the corresponding BeanPostProcessor declaration and its dependencies/advisors. If this bean does not have to be post-processed, declare it with ROLE_INFRASTRUCTURE. 2025-03-28 18:40:37 WARN 47864 --- [GraduateProject-projectService] [ main] tra
03-29
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值