Bean ‘securityManager‘ of type [org.apache.shiro.web.mgt.DefaultWebSecurityManager] is not eligible

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)

问题. 

其实遇到这个打印了一堆INFO的问题, 问题不大, 简单来说我遇到这个问题是由于配置Shiro与Spring Boot整合时才会出现的问题, 原因是与Spring整合的这个ShiroFilterFactoryBean这个类实现了BeanPostProcessor这些接口, 这意味着这些东西需要非常非常早执行, 甚至早于你的Reaml的实例化, 所以对于在这个BeanPostProcessor阶段被依赖的类来说, 他们无法被Spring正常代理, (意思就是如果你的Reaml里注入了其他Service, 它无法获得代理后的特性, 比如事务), 但这个并不影响Shiro的使用, 因为Shiro在进行Authentication或者Authorization时也不需要Service或者Mapper处理事务, 它只是简单的查询, 所以其实这个问题不是大问题. 在 https://issues.apache.org/jira/browse/SHIRO-743 也有提到这个问题, 目前因为没什么大影响. (弱弱bb一句为什么这个问题从Shiro1.2带到1.6......)

如果你和我一样是强迫症患者, 你可以将SecurityManager Bean设置为延时加载, 这样就不会有一堆一堆的东西了...(当然还是会有一个)

 

这是修改前: 

这是修改后: 

是否感受到一阵酸爽...要是有更好的解决办法记得告诉我. 看到这里就意味着有机会你就要大补一下Spring框架了. 

该错误提示表明在项目中没有找到类型为 `org.apache.shiro.realm.Realm` 的 Bean。通常情况下,我们需要在 Spring Boot 的配置文件中配置一个 `Realm` 的 Bean。 您可以按照以下步骤来解决该问题: 1. 在项目中添加 Apache Shiro 的依赖,例如: ```xml <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-spring</artifactId> <version>1.7.1</version> </dependency> ``` 2. 在 Spring Boot 的配置文件中配置 `Realm` 的 Bean,例如: ```java @Configuration public class ShiroConfig { @Bean public Realm realm() { // 返回一个 Realm 的实现类 } @Bean public SecurityManager securityManager() { DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager(); securityManager.setRealm(realm()); return securityManager; } // 其他的 Shiro 相关配置 } ``` 在上述代码中,我们定义了一个 `Realm` 的 Bean,并在 `securityManager()` 方法中将该 `Realm` 实例设置为默认的安全管理器。 3. 在需要使用安全管理器的地方,注入 `SecurityManager` 的 Bean,并使用该 Bean 进行相关操作,例如: ```java @RestController public class UserController { @Autowired private SecurityManager securityManager; @GetMapping("/user") public String getUser() { SecurityUtils.setSecurityManager(securityManager); // 其他的 Shiro 相关操作 } } ``` 在上述代码中,我们注入了 `SecurityManager` 的 Bean,并在 `getUser()` 方法中使用该 Bean 进行相关操作。 通过以上步骤,您应该可以解决该错误提示。如果仍然存在问题,您可以仔细检查一下代码,或者提供更多的错误信息,以便更好地定位问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值