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接口。
解决方案
方案1:延迟初始化
其他网址
Spring--BeanPostProcessor--注意/问题/坑--SpringBoot_IT利刃出鞘的博客-CSDN博客
Spring(SpringBoot)--延迟加载(@Lazy注解等)--使用/原理_IT利刃出鞘的博客-CSDN博客
简介
可以使用延迟初始化来解决。延迟初始化会在IOC的时候先给出一个代理类,IOC之后的AOP这个BeanPostProcessor会正常地给它处理。
具体做法
加一个注解即可:@Lazy。可以在两个地方加这个注解:字段、方法参数。
方案1:加到字段上
import org.springframework.context.annotation.Lazy;
import org.apache.shiro.realm.AuthorizingRealm;public class DatabaseRealm extends AuthorizingRealm {@Lazy@Autowiredprivate UserService userService;
}
方案2:加到构造方法的参数上
import org.springframework.context.annotation.Lazy;
import org.apache.shiro.realm.AuthorizingRealm;public class DatabaseRealm extends AuthorizingRealm {private UserService userService;public DatabaseRealm(@Lazy @Autowired UserService userService){this.userService = userService;}
}
修改之后的输出
我把业务有关的数据库Service都加上了@Lazy。就是这几个:UserService、OrderService、ProductService。
2021-08-14 20:03:12.810 INFO 8232 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.apache.shiro.spring.boot.autoconfigure.ShiroBeanAutoConfiguration' of type [org.apache.shiro.spring.boot.autoconfigure.ShiroBeanAutoConfiguration$$EnhancerBySpringCGLIB$$a5a744cc] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-08-14 20:03:12.833 INFO 8232 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.apache.shiro.spring.boot.autoconfigure.ShiroAnnotationProcessorAutoConfiguration' of type [org.apache.shiro.spring.boot.autoconfigure.ShiroAnnotationProcessorAutoConfiguration$$EnhancerBySpringCGLIB$$a83a8371] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-08-14 20:03:12.866 INFO 8232 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'shiroConfig' of type [com.example.demo.config.shiro.ShiroConfig$$EnhancerBySpringCGLIB$$4242a0c5] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-08-14 20:03:13.297 INFO 8232 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'hashedCredentialsMatcher' of type [org.apache.shiro.authc.credential.HashedCredentialsMatcher] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-08-14 20:03:13.315 INFO 8232 --- [ 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 20:03:13.319 INFO 8232 --- [ 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 20:03:13.321 INFO 8232 --- [ 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 20:03:13.326 INFO 8232 --- [ 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 20:03:13.342 INFO 8232 --- [ 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 20:03:13.349 INFO 8232 --- [ 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 20:03:13.352 INFO 8232 --- [ 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 20:03:13.356 INFO 8232 --- [ 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 20:03:13.358 INFO 8232 --- [ 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 20:03:13.385 INFO 8232 --- [ 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 20:03:13.387 INFO 8232 --- [ 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 20:03:13.388 INFO 8232 --- [ 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 20:03:13.402 INFO 8232 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.apache.shiro.spring.config.web.autoconfigure.ShiroWebFilterConfiguration' of type [org.apache.shiro.spring.config.web.autoconfigure.ShiroWebFilterConfiguration$$EnhancerBySpringCGLIB$$fcae0a6d] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-08-14 20:03:13.410 INFO 8232 --- [ 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)
可以看到,这几个Service的输出就没有了。
但是,还有其他的bean会报这个问题。报就报吧,只要他没影响到功能就行。
方案2:@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
简介
方案说明
在Bean的声明上加个注解:@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
表明这个bean是完全后台模式,不需要被代理。
需要注意的是,我们的Realm需要操作数据库,它里边依赖的Service(例如UserService)仍然需要被代理。所以,上边“方案1”的延迟初始化仍然需要加到UserService等Service上。
原理
Spring 容器初始化时会在refresh方法中执行 registerBeanPostProcessors(beanFactory);
此方法为容器增加了一个BeanPostProcessorChecker这个BeanPostProcessor,它会记录下当前的BeanPostProcessor数量。方法位置是:org.springframework.context.support.PostProcessorRegistrationDelegate.BeanPostProcessorChecker#postProcessAfterInitialization
代码如下:
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) {if (!(bean instanceof BeanPostProcessor) && !isInfrastructureBean(beanName) &&this.beanFactory.getBeanPostProcessorCount() < this.beanPostProcessorTargetCount) {if (logger.isInfoEnabled()) {logger.info("Bean '" + beanName + "' of type [" + bean.getClass().getName() +"] is not eligible for getting processed by all BeanPostProcessors " +"(for example: not eligible for auto-proxying)");}}return bean;
}
满足了三个条件才会打印这个日志,
1. bean 没有实现BeanPostProcesor
2. 不是 isInfrastructureBean,
3. 之前记录的BeanPostProcess数量少于当前的数量。
测试
在Shiro的总配置类上的所有Bean上都加上@Role(BeanDefinition.ROLE_INFRASTRUCTURE)。
代码示例:
package com.example.demo.config.shiro;import com.example.demo.common.constant.WhiteList;
import com.example.demo.config.shiro.filter.JwtFilter;
import com.example.demo.config.shiro.realm.AccountRealm;
import org.apache.shiro.authc.credential.HashedCredentialsMatcher;
import org.apache.shiro.mgt.DefaultSessionStorageEvaluator;
import org.apache.shiro.mgt.DefaultSubjectDAO;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor;
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
import org.apache.shiro.spring.web.config.DefaultShiroFilterChainDefinition;
import org.apache.shiro.spring.web.config.ShiroFilterChainDefinition;
import org.apache.shiro.web.filter.authc.AuthenticatingFilter;
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Role;import javax.servlet.Filter;
import java.util.LinkedHashMap;
import java.util.Map;@Configuration
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public class ShiroConfig {@Bean@Role(BeanDefinition.ROLE_INFRASTRUCTURE)public ShiroFilterChainDefinition shiroFilterChainDefinition() {DefaultShiroFilterChainDefinition chainDefinition = new DefaultShiroFilterChainDefinition();chainDefinition.addPathDefinition("/login", "anon");WhiteList.ALL.forEach(str -> {chainDefinition.addPathDefinition(str, "anon");});// all other paths require a logged in userchainDefinition.addPathDefinition("/**", "jwt");return chainDefinition;}/*** 设置过滤器,将自定义的Filter加入。*/@Bean("shiroFilterFactoryBean")@Role(BeanDefinition.ROLE_INFRASTRUCTURE)public ShiroFilterFactoryBean shiroFilterFactoryBean(SecurityManager securityManager) {ShiroFilterFactoryBean factoryBean = new ShiroFilterFactoryBean();// 登录的地址factoryBean.setLoginUrl("/login");// 登录成功后要跳转的地址// factoryBean.setSuccessUrl("/index");// 未授权地址// factoryBean.setUnauthorizedUrl("/unauthorized");factoryBean.setSecurityManager(securityManager);Map<String, Filter> filterMap = factoryBean.getFilters();filterMap.put("jwt", new JwtFilter());factoryBean.setFilters(filterMap);factoryBean.setFilterChainDefinitionMap(shiroFilterChainDefinition().getFilterChainMap());return factoryBean;}@Bean@Role(BeanDefinition.ROLE_INFRASTRUCTURE)public DefaultWebSecurityManager securityManager() {DefaultSubjectDAO subjectDAO = new DefaultSubjectDAO();DefaultSessionStorageEvaluator defaultSessionStorageEvaluator = new DefaultSessionStorageEvaluator();// 关闭shiro自带的session。这样不能通过session登录shiro,后面将采用jwt凭证登录。// 见:http://shiro.apache.org/session-management.html#SessionManagement-DisablingSubjectStateSessionStoragedefaultSessionStorageEvaluator.setSessionStorageEnabled(false);subjectDAO.setSessionStorageEvaluator(defaultSessionStorageEvaluator);DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();securityManager.setRealm(getDatabaseRealm());securityManager.setSubjectDAO(subjectDAO);return securityManager;}@Bean@Role(BeanDefinition.ROLE_INFRASTRUCTURE)public AccountRealm getDatabaseRealm() {return new AccountRealm();}/*** setUsePrefix(true)用于解决一个奇怪的bug。如下:* 在引入spring aop的情况下,在@Controller注解的类的方法中加入@RequiresRole等* shiro注解,会导致该方法无法映射请求,导致返回404。加入这项配置能解决这个bug。*/@Bean@Role(BeanDefinition.ROLE_INFRASTRUCTURE)public static DefaultAdvisorAutoProxyCreator getDefaultAdvisorAutoProxyCreator(){DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator=new DefaultAdvisorAutoProxyCreator();defaultAdvisorAutoProxyCreator.setUsePrefix(true);return defaultAdvisorAutoProxyCreator;}
}
启动结果
. ____ _ __ _ _/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \\\/ ___)| |_)| | | | | || (_| | ) ) ) )' |____| .__|_| |_|_| |_\__, | / / / /=========|_|==============|___/=/_/_/_/:: Spring Boot :: (v2.3.8.RELEASE)2022-05-18 19:16:52.898 INFO 4824 --- [ main] com.example.demo.ShiroApplication : Starting ShiroApplication on DESKTOP-QI6B9ME with PID 4824 (E:\work\Idea_proj\shiro\shiro_3_jwt\target\classes started by Liu in E:\work\Idea_proj\shiro\shiro_3_jwt)
2022-05-18 19:16:52.901 INFO 4824 --- [ main] com.example.demo.ShiroApplication : No active profile set, falling back to default profiles: default
2022-05-18 19:16:53.884 INFO 4824 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.apache.shiro.spring.boot.autoconfigure.ShiroBeanAutoConfiguration' of type [org.apache.shiro.spring.boot.autoconfigure.ShiroBeanAutoConfiguration$$EnhancerBySpringCGLIB$$88a9810a] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2022-05-18 19:16:53.972 INFO 4824 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.apache.shiro.spring.boot.autoconfigure.ShiroAnnotationProcessorAutoConfiguration' of type [org.apache.shiro.spring.boot.autoconfigure.ShiroAnnotationProcessorAutoConfiguration$$EnhancerBySpringCGLIB$$8b3cbfaf] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2022-05-18 19:16:54.477 INFO 4824 --- [ 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)
2022-05-18 19:16:54.489 INFO 4824 --- [ 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)
2022-05-18 19:16:54.702 INFO 4824 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2022-05-18 19:16:54.711 INFO 4824 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-05-18 19:16:54.711 INFO 4824 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.41]
2022-05-18 19:16:54.817 INFO 4824 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-05-18 19:16:54.817 INFO 4824 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1872 ms
Logging initialized using 'class org.apache.ibatis.logging.stdout.StdOutImpl' adapter.
Property 'mapperLocations' was not specified._ _ |_ _ _|_. ___ _ | _
| | |\/|_)(_| | |_\ |_)||_|_\ / | 3.4.3.1
2022-05-18 19:16:56.483 INFO 4824 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2022-05-18 19:16:56.764 INFO 4824 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2022-05-18 19:16:56.947 INFO 4824 --- [ main] com.example.demo.ShiroApplication : Started ShiroApplication in 4.399 seconds (JVM running for 5.471)
可见,“is not eligible for getting processed by all BeanPostProcessors”警告已经少了很多,但还是有4个类的警告:ShiroBeanAutoConfiguration、ShiroAnnotationProcessorAutoConfiguration、AuthorizationAttributeSourceAdvisor、DefaultEventBus。
上边这4个是Shiro包里边的类,我们无法处理。
思考
如何完全去掉“is not eligible for getting processed by all BeanPostProcessors”这个输出?
很不幸,没有办法。Shiro它在关键的bean处实现了BeanPostProcessor接口,它又依赖了其他东西,就会导致其他东西提前IOC,无法AOP。
一个很好的权限框架应该是这样的:
- 可以方便配置使用session或者token
- 可以方便配置session或token的超时时间
- 不实现BeanPostProcessor
- 提供无需身份认证的注解,这个注解可以加到方法或者类上
- 默认支持主流的缓存技术:Redis、Memcache、单机版。而且可配置、可自定义读写缓存的逻辑
- 支持前后端一体的和前后端分离的场景,可以通过配置来切换。
- 比如:我想前后端分离,就用不到shiro里边的loginUrl、successUrl、unauthorizedUrl
其他网址
Bean生命周期--BeanPostProcessor-坑_IT利刃出鞘的博客-CSDN博客
业务类无法被AOP代理问题
Shiro--解决is not eligible for getting processed by all BeanPostProcessors相关推荐
- 解决:is not eligible for getting processed by all BeanPostProcessors
文章目录 问题描述 分析 总结 解决 方案1:延迟初始化 方案2:@Role(BeanDefinition.ROLE_INFRASTRUCTURE) 参考 问题描述 SpringBoot项目整合Shi ...
- springboot+shiro is not eligible for getting processed by all BeanPostProcessors
项目背景: 服务基于springboot搭建,shiro做认证鉴权,本地启动正常,打包正常,服务器启动正常,采用jenkins打包部署服务,偶尔出现问题 原因分析: 因为问题是偶现的,当时觉得是环境问 ...
- is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for
springboot项目创建常见问题(持续更新!) https://blog.csdn.net/libusi001/article/details/97267365 Bean 'org.springf ...
- 排查not eligible for getting processed by all BeanPostProcessors
前言 上一篇文章我们聊了一下自定义实现的SPI如何与spring进行整合,但其实在实现的过程中有个小细节,就是原先我们的SPI是带了拦截器功能,(ps:对如何实现一个带拦截器的SPI感兴趣的朋友,可以 ...
- is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-
springboot项目创建常见问题(持续更新!) springboot项目创建常见问题(建议收藏!!!) 目录 一.报错信息 二.信息解析 三.解决方法 四.其他解决方案 一.报错信息 Bean ' ...
- 问题记录:is not eligible for getting processed by all BeanPostProcessors
场景: spring aop使用过程遇到的异常信息的解决过程记录 问题描述 问题代码如下: @Configuration public class LogConfig {@Beanpublic Jdk ...
- fixed bug: is not eligible for getting processed by all BeanPostProcessors
因项目需要,去掉consul能力,但是编辑好了yml文件出现如下错误,一直读不到配置文件 报如下的错误: 已连接到目标 VM, 地址: ''127.0.0.1:51162',传输: '套接字'' 20 ...
- SpringBoot项目启动失败: is not eligible for getting processed by all BeanPostProcessors (for example: not)
SpringBoot项目启动失败报错: ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$f4a94db ...
- 提示BeanPostProcessorChecker:is not eligible for getting processed by all BeanPostProcessors的原因
今天有读者朋友反馈在调试本书15章的源码时出现"BeanPostProcessorChecker:xxx is not eligible for getting processed by a ...
最新文章
- linux进程间通信:system V 信号量 生产者和消费者模型编程案例
- linux算术表达式求值数据结构,数据结构:算数表达式求值演示
- Android -ui控件
- 洛谷——P1092 虫食算
- android 面试题(一)
- r语言调用python_小众做法,通过python调用R语言的第三方包
- Linux下snmp常用的OID ---- SNMP硬件监控
- c语言解析sql语句_解析SQL语句比解析类C语言更麻烦?
- MySql添加外键报错:Cannot add foreign key constraint
- VMWare网络连接方式与设置
- 拓端tecdat|R语言对巨灾风险下的再保险合同定价研究案例:广义线性模型和帕累托分布Pareto distributions分析
- 迅雷精简版 for Mac(迅雷下载器)v4.1.2中文版
- cad补全三视图_cad补画三视图练习题.doc
- 如何通过付费咨询,薅知乎的羊毛?
- -bash: /usr/bin/rm: 参数列表过长
- 为什么面试完,总是让你回去等通知?
- 面试中经常被问到Java引用类型原理,带你深入剖析
- 安全问题的思考---君子不立于危墙之下
- update(更新) 和 upgrade(升级)
- Android 7.0模拟来电