项目背景
公司内部某架构系统,在shrio realm中注入使用了RedisUtils
@Autowired
RedisUtils redisUtils;
问题描述
本身项目的redis
是使用aop
在yml
控制开关的,但是突然发现aop
失效了,无法开关redis在控制台没有报错出现但是有如下输出:
Bean 'shiroConfig' of type [com.jack.modules.njp.security.config.ShiroConfig$$EnhancerBySpringCGLIB$$7aac9763] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-12-02 15:33:31.267 INFO 7908 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'spring.redis-org.springframework.boot.autoconfigure.data.redis.RedisProperties' of type [org.springframework.boot.autoconfigure.data.redis.RedisProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-12-02 15:33:31.270 INFO 7908 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.boot.autoconfigure.data.redis.LettuceConnectionConfiguration' of type [org.springframework.boot.autoconfigure.data.redis.LettuceConnectionConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-12-02 15:33:31.348 INFO 7908 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'lettuceClientResources' of type [io.lettuce.core.resource.DefaultClientResources] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-12-02 15:33:31.401 INFO 7908 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'redisConnectionFactory' of type [org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-12-02 15:33:31.401 INFO 7908 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'redisConfig' of type [com.jack.common.redis.RedisConfig$$EnhancerBySpringCGLIB$$4dab53ba] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-12-02 15:33:31.509 INFO 7908 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'redisTemplate' of type [org.springframework.data.redis.core.RedisTemplate] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-12-02 15:33:31.510 INFO 7908 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'redisUtils' of type [com.jack.common.redis.RedisUtils] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-12-02 15:33:31.510 INFO 7908 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'oauth2Realm' of type [com.jack.modules.njp.security.oauth2.Oauth2Realm] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-12-02 15:33:31.516 INFO 7908 --- [ 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-12-02 15:33:31.643 INFO 7908 --- [ 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-12-02 15:33:31.688 INFO 7908 --- [ 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-12-02 15:33:31.871 INFO 7908 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.integration.config.IntegrationManagementConfiguration' of type [org.springframework.integration.config.IntegrationManagementConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-12-02 15:33:31.886 INFO 7908 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'integrationChannelResolver' of type [org.springframework.integration.support.channel.BeanFactoryChannelResolver] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-12-02 15:33:31.888 INFO 7908 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'integrationDisposableAutoCreatedBeans' of type [org.springframework.integration.config.annotation.Disposables] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-12-02 15:33:32.143 INFO 7908 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer :
就突然发现有关于redisUtils的问题
redisUtils' of type [com.jack.common.redis.RedisUtils] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
翻译一下意思是 :该bean无法被所有的BeanPostProcessors
处理(例如:无法创建自动代理)
无法aop本身就是基于代理实现的,现在无法获取代理类aop自然无法实现了。
问题解决
@Component
public class Oauth2Realm extends AuthorizingRealm {
@Lazy
@Autowired
private ShiroService shiroService;
@Lazy
@Autowired
RedisUtils redisUtils;
}
将realm 注入的autowired
加上懒加载即可
原因分析
参考https://www.cnblogs.com/micrari/p/7354650.html bean的创建过程
org.springframework.beans.factory.support.AbstractBeanFactory
#doGetBean
打断点
很久才能进来
往前找依赖
redisUtils->oauth2Realm
redisUtils->oauth2Realm->securityManager
redisUtils->oauth2Realm->securityManager->shiroFilter
redisUtils->oauth2Realm->securityManager->shiroFilter->shiroConfig
在这里已经看到了shiroFilter
是postprocessor
@Bean("shiroFilter")
public ShiroFilterFactoryBean shirFilter(SecurityManager securityManager) {
ShiroFilterFactoryBean shiroFilter = new ShiroFilterFactoryBean();
shiroFilter.setSecurityManager(securityManager);
}
public class ShiroFilterFactoryBean implements FactoryBean, BeanPostProcessor {
因为作为我们的redisUtils作为了postprocessor的依赖则无法创建代理