记一次实际开发中问题,启动控制台日志打印 (for example: not eligible for auto-proxying)

问题是:项目启动控制台日志打印 is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)具体信息如下(只复制了部分)


17:42:06.621 [main] INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'shiroConfiguration' of type [com.cn.shiro.ShiroConfiguration$$EnhancerBySpringCGLIB$$3152df87] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
17:42:07.582 [main] INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'sysMenuMapper' of type [com.sun.proxy.$Proxy57] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
17:42:07.583 [main] INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'sysMenuServiceImpl' of type [com.cn.sys.service.impl.SysMenuServiceImpl] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
17:42:07.589 [main] INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'sysUserMapper' of type [com.sun.proxy.$Proxy60] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
17:42:07.589 [main] INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'sysUserServiceImpl' of type [com.cn.sys.service.impl.SysUserServiceImpl] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

17:42:07.589 [main] INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'myShiroRealm' of type [com.cn.shiro.MyShiroRealm] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

17:42:07.666 [main] INFO  o.s.c.s.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$67a6d22a] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

不影响启动。但是上网查了下说会影响事物,所以开始各种找资料,顺便记个流水账。


得到的答案是:因为集成了shiro,配置shiroFilter,shiroFilter依赖了securityManagersecurityManager依赖了userRealmuserRealm为了获取AuthenticationInfo和AuthorizationInfo又依赖了SysuserService等其他bean。导致业务bean在BPP实例化前被实例化了。理想情况下应该让spring先实例化所有的BPP后,再实例化我们的业务bean,这样业务bean才能被所有BPP处理,如果有业务bean先于任何BPP实例化,那么这个业务bean就不会被还未实例化的BPP处理了,这个就是上面日志提示的原因。所以是 shiroFilter导致了SysuserService等其他bean没有被@Transactional 对应的BPP处理,导致事务不起作用。虽然spring打印很多bean,一般最后打印的那个bean是导致问题的罪魁祸首,因为spring是先实例化被依赖的bean。


最后解决方案是

解决方法1
用 getApplicationContext().getBean() 获取注入对象

解决方法2:
获取 AuthenticationInfoAuthorizationInfo不要通过UserService/UserRoleService,可以单独写个Service或Dao供登录使用。


附上其他不错的参考:
引入shiro后userService事务不生效原因:
https://www.jianshu.com/p/b1209cd3686d
Spring BPP中优雅的创建动态代理Bean:
https://www.cnblogs.com/hujunzheng/p/10463798.html

你可能感兴趣的:(java,架构,springboot)