spring boot 整合shiro 错误

简介 最近在弄springboot整合shiro的。这里记录其中一个错误:1:NoSecurityManageraccessibletothecallingcode,eitherboundtotheorg.apache.shiro.util.ThreadContextorasavmstaticsingleton. Thisisaninvalidapplicationconfiguration.

🔔🔔好消息!好消息!🔔🔔

 如果您需要注册ChatGPT,想要升级ChatGPT4。凯哥可以代注册ChatGPT账号代升级ChatGPT4

有需要的朋友👉:微信号 kaigejava2022

最近在弄spring boot 整合shiro的。这里记录其中一个错误:

1:No SecurityManager accessible to the calling code, either bound to the org.apache.shiro.util.ThreadContext or as a vm static singleton.  This is an invalid application configuration.




各种搜索:发现相关的



说web.xml中没有添加shiro相关的拦截器。凯哥现在用的是spring boot。web.xml没有。但是凯哥配置了shiro的核心拦截器啊。如下图:



并且使用了@Configuration这个注解了。可是为什么还是会报错呢?

在好好看看人家的分析,说是web.xml文件中没有添加。我使用了@Configuration理论上,spring boot会自动加载啊。回头在看看spring boot启动类:



好像没问题啊。因为在没有基础shiro的时候,项目还是正常运行的。在细细一看,感觉好像还是不对。为什么呢?

因为我们使用了@Configuration这个注解,而在spring boot启动类似我们只配置了scanBasePackages和mapperscan这两个注解。但是configuration这个注解不在上面两个扫描范围中啊。分析到原因后,解决方案就是让这个注解spirng boot也能管理就可以看了。所以果断在上面添加@componenScan这个注解。

如下图:



添加后,重启继续访问登录:



登录成功。成功。

总结:

网上有很多成熟的spring 整合shrio的代码。如果对spring boot注解了解的话。其实很容易就整合的。


TopTop