发布时间:2024-05-31 14:01
常见事务失效原因:
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的失效