Shiro--解决is not eligible for getting processed by all BeanPostProcessors

原文网址:Shiro--解决is not eligible for getting processed by all BeanPostProcessors_IT利刃出鞘的博客-CSDN博客

简介

说明

本文介绍使用SpringBoot整合Shiro时打印"is not eligible for getting processed by all BeanPostProcessors"的原因以及解决方案。

问题描述

使用SpringBoot整合Shiro时发现有如下输出:

2021-08-14 17:53:25.145  INFO 80884 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'sqlSessionFactory' of type [org.apache.ibatis.session.defaults.DefaultSqlSessionFactory] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-08-14 17:53:25.152  INFO 80884 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'sqlSessionTemplate' of type [org.mybatis.spring.SqlSessionTemplate] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-08-14 17:53:25.367  INFO 80884 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'userMapper' of type [org.mybatis.spring.mapper.MapperFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-08-14 17:53:25.369  INFO 80884 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'userMapper' of type [com.sun.proxy.$Proxy63] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-08-14 17:53:25.378  INFO 80884 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'userServiceImpl' of type [com.example.demo.business.rbac.user.service.impl.UserServiceImpl] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-08-14 17:53:25.444  INFO 80884 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'roleMapper' of type [org.mybatis.spring.mapper.MapperFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-08-14 17:53:25.445  INFO 80884 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'roleMapper' of type [com.sun.proxy.$Proxy67] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-08-14 17:53:25.448  INFO 80884 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'roleServiceImpl' of type [com.example.demo.business.rbac.role.service.impl.RoleServiceImpl] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-08-14 17:53:25.482  INFO 80884 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'permissionMapper' of type [org.mybatis.spring.mapper.MapperFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-08-14 17:53:25.483  INFO 80884 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'permissionMapper' of type [com.sun.proxy.$Proxy69] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-08-14 17:53:25.485  INFO 80884 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'permissionServiceImpl' of type [com.example.demo.business.rbac.permission.service.impl.PermissionServiceImpl] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-08-14 17:53:25.486  INFO 80884 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'getDatabaseRealm' of type [com.example.demo.config.shiro.realm.DatabaseRealm] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-08-14 17:53:25.491  INFO 80884 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'sessionManager' of type [org.apache.shiro.web.session.mgt.DefaultWebSessionManager] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-08-14 17:53:25.493  INFO 80884 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'securityManager' of type [org.apache.shiro.web.mgt.DefaultWebSecurityManager] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-08-14 17:53:25.504  INFO 80884 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'authorizationAttributeSourceAdvisor' of type [org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-08-14 17:53:25.530  INFO 80884 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'eventBus' of type [org.apache.shiro.event.support.DefaultEventBus] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-08-14 17:53:25.539  INFO 80884 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'shiroFilterChainDefinition' of type [org.apache.shiro.spring.web.config.DefaultShiroFilterChainDefinition] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-08-14 17:53:25.543  INFO 80884 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'requestContextFilter' of type [org.springframework.boot.web.servlet.filter.OrderedRequestContextFilter] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-08-14 17:53:25.551  INFO 80884 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration' of type [org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-08-14 17:53:25.555  INFO 80884 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'formContentFilter' of type [org.springframework.boot.web.servlet.filter.OrderedFormContentFilter] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-08-14 17:53:25.573  INFO 80884 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'server-org.springframework.boot.autoconfigure.web.ServerProperties' of type [org.springframework.boot.autoconfigure.web.ServerProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-08-14 17:53:25.575  INFO 80884 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.boot.autoconfigure.web.servlet.HttpEncodingAutoConfiguration' of type [org.springframework.boot.autoconfigure.web.servlet.HttpEncodingAutoConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-08-14 17:53:25.576  INFO 80884 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'characterEncodingFilter' of type [org.springframework.boot.web.servlet.filter.OrderedCharacterEncodingFilter] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-08-14 17:53:25.601  INFO 80884 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.apache.shiro.spring.config.web.autoconfigure.ShiroWebFilterConfiguration' of type [org.apache.shiro.spring.config.web.autoconfigure.ShiroWebFilterConfiguration$$EnhancerBySpringCGLIB$$2285dfd6] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-08-14 17:53:25.615  INFO 80884 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'globalFilters' of type [java.util.Collections$SingletonList] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-08-1

发现这个信息一直在输出:

Bean 'xxx' of type [com.example.demo.business.rbac.user.service.impl.UserServiceImpl] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

中文描述

意思是:xxx这个bean不能被所有的BeanPostProcessors处理(比如:自动代理(即:AOP))

这个输出可能引起的问题

我们知道,Spring的很多逻辑是用AOP实现的,比较重要的一个就是:数据库的事务。如果事务不能被代理的话,那么Spring将无法控制事务(比如:提交、回滚)。

原因解析

简介

依赖了UserService的某个bean实现了BeanPostProcessor之类的接口,导致UserServiceImpl被提前注入,导致无法被AOP。

断点调试

1.打条件断点

在SpringBoot的代码中获得userServiceImpl这个bean的地方打断点,看是哪个特殊的bean最终依赖了userServiceImpl这个bean。

打条件断点:

我如何知道在哪里打断点的?

这个就要了解Bean的创建过程了,见:Spring--Bean生命周期--流程/原理--SpringBoot_IT利刃出鞘的博客-CSDN博客_springboot中bean的生命周期

所以,本处的断点可以打在下边这些的任意一个方法里边:

  • AbstractBeanFactory#getBean
  • AbstractBeanFactory#doGetBean
  • AbstractAutowireCapableBeanFactory#createBean
  • AbstractAutowireCapableBeanFactory#doCreateBean 

2.进入断点

在上边的箭头处沿着栈信息往前找,看它是如何依赖到UserServiceImpl的。

前边是bean的类型,后边是bean的名字。有的bean没类型(required为null),只有bean名字。
org.springframework.beans.factory.config.BeanPostProcessor(webMvcObjectMapperConfigurer)
    org.springframework.aop.Advisor(org.springframework.transaction.config.internalTransactionAdvisor)
        (org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration)
            org.springframework.aop.Advisor(authorizationAttributeSourceAdvisor)
                (securityManager)
                    (getDatabaseRealm) //这个是我代码中自定义的Realm的用@Bean注册时的方法名
                        (userServiceImpl)

一目了然了。我代码里边是webMvcObjectMapperConfigurer这个BeanPostProcessor的实现类最终依赖到了UserServiceImpl。它使UserServiceImpl提前被IOC,无法被AOP了。

注意

本处我的代码是webMvcObjectMapperConfigurer这个BeanPostProcessor的实现类最终依赖到了UserServiceImpl。

这个与个人的Shiro使用方式有关,我是在代码里提供了下边这个bean,所以才会这样

/**
 * 开启shiro aop注解支持.
 * 使用代理方式;所以需要开启代码支持;
 *
 * @param securityManager
 * @return
 */
@Bean
public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(
        SecurityManager securityManager) {
    AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor =
            new AuthorizationAttributeSourceAdvisor();
    authorizationAttributeSourceAdvisor.setSecurityManager(securityManager);
    return authorizationAttributeSourceAdvisor;
}

如果提供了ShiroFilterFactoryBean这个bean,也会导致“is not eligible for getting processed by all BeanPostProcessors”这个问题,因为它也实现了BeanPostProcessor接口。

解决方案

上边是文章的部分内容,为便于维护,全文已转移到此网址:Shiro-解决is not eligible for getting processed by all BeanPostProcessors - 自学精灵

评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

IT利刃出鞘

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值