springboot 继承shiro 使用redis缓存 @Value 标签无效 无法获取值

在开发中使用了shiro作为权限管理,之前也没管shiro的缓存问题,就是会有点打印日志说没缓存,今天抽时间想加一下redis的缓存,一查还挺简单,但是在使用@Valle获取redis配置的时候发现无法获取:
@Value(“ redis.host)privateStringhost;@Value( {redis.port}”)
private int port;

获取不到的原因:

然后发现两种方案 参考文档 参考文档中提到的stackoverflow
一、注释掉
将shiroConfig里那段代码注释

@Bean(name = "lifecycleBeanPostProcessor")
public  LifecycleBeanPostProcessor getLifecycleBeanPostProcessor() {
    return new LifecycleBeanPostProcessor();
}

二、
将shiroConfig里那段代码改成

@Bean(name = "lifecycleBeanPostProcessor")
public static LifecycleBeanPostProcessor getLifecycleBeanPostProcessor() {
    return new LifecycleBeanPostProcessor();
}

就能正常获取数据了
推荐使用第二种

猜你喜欢

转载自blog.csdn.net/z1729734271/article/details/78930292