springboot @Transactional注解与@Async注解失效

常见事务失效原因:

1.内部调用(常见于同一个service引用了本service的方法,且最开始的方法没有打上注解)

2.没有指定监听的Exception(常见于抛出的异常非RuntimeException及其子类)

3.异常被方法内部try catch掉了,未向外抛出

4.方法不是public的

而我出现的场景并不在上述的原因列表中,且伴随着@Async注解也失效了,其实是由于Spring 的Aop失效导致的,并可观测出,在controller层拿到的springboot自动注入的service对象并非代理对象。

此问题通常还伴随着程序启动时,会输出这类的日志:

[com.landray.ldingbridge3.agent.core.service.impl.RoleMenuRelationServiceImpl] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
traceId:[],tenantId:[] 2022-01-04 15:02:10.804  INFO 24056 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'rolePermRelationMapper' of type [org.mybatis.spring.mapper.MapperFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
traceId:[],tenantId:[] 2022-01-04 15:02:10.805  INFO 24056 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'rolePermRelationMapper' of type [com.sun.proxy.$Proxy111] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
traceId:[],tenantId:[] 2022-01-04 15:02:10.806  INFO 24056 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'rolePermRelationServiceImpl' of type [com.landray.ldingbridge3.agent.core.service.impl.RolePermRelationServiceImpl] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
traceId:[],tenantId:[] 2022-01-04 15:02:10.810  INFO 24056 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'userRoleRelationMapper' of type [org.mybatis.spring.mapper.MapperFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
traceId:[],tenantId:[] 2022-01-04 15:02:10.811  INFO 24056 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'userRoleRelationMapper' of type [com.sun.proxy.$Proxy112] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
traceId:[],tenantId:[] 2022-01-04 15:02:10.813  INFO 24056 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'userRoleRelationServiceImpl' of type [com.landray.ldingbridge3.agent.core.service.impl.UserRoleRelationServiceImpl] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
traceId:[],tenantId:[] 2022-01-04 15:02:10.818  INFO 24056 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'userInfoMapper' of type [org.mybatis.spring.mapper.MapperFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
traceId:[],tenantId:[] 2022-01-04 15:02:10.819  INFO 24056 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'userInfoMapper' of type [com.sun.proxy.$Proxy113] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
traceId:[],tenantId:[] 2022-01-04 15:02:10.826  INFO 24056 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'deptInfoMapper' of type [org.mybatis.spring.mapper.MapperFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
traceId:[],tenantId:[] 2022-01-04 15:02:10.827  INFO 24056 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'deptInfoMapper' of type [com.sun.proxy.$Proxy114] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
traceId:[],tenantId:[] 2022-01-04 15:02:10.831  INFO 24056 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'deptUserRelationMapper' of type [org.mybatis.spring.mapper.MapperFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
traceId:[],tenantId:[] 2022-01-04 15:02:10.832  INFO 24056 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'deptUserRelationMapper' of type [com.sun.proxy.$Proxy115] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

表示springboot在提醒开发者,这些类并未被spring所包装,之前一直忽视了这个问题,知道出现事务失效的问题才来寻找原因,最后定位到这里,发现是由于shiro导致的。

最后解决:

解析:由于shiro的这个realm需要在程序一启动的时候马上实例化,而这时spring的bean处理器还未对service对象包装成代理对象,所有就将未代理的原始对象进行了注入,而导致AOP的失效

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值