避坑一
异常打印
org.apache.shiro.UnavailableSecurityManagerException:
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中添加DelegatingFilterProxy
。
但是,本文的整合是在Spring Boot环境中进行测试的,并未使用web.xml文件,如果加上web.xml文件会显得整个工程不伦不类的。因此果断舍弃这种解决方法。那应该怎么解决呢?
原因
用shiro-spring-boot-starter
,是不支持web的。准确说缺少一部分对web的常用类的支持
解决办法
Shiro has first-class support for Spring web applications. In a web application, all Shiro-accessible web requests must go through a master Shiro Filter. This filter itself is extremely powerful, allowing for ad-hoc custom filter chains to be executed based on any URL path expression.
First include the Shiro Spring web starter dependency in you application classpath (we recomend using a tool such as Apache Maven or Gradle to manage this).
翻译:
Shiro对Spring Web应用程序提供了一流的支持。 在Web应用程序中,所有Shiro可访问的Web请求都必须通过 Shiro过滤器。 该过滤器本身非常强大,可以根据任何URL路径表达式执行临时自定义过滤器链。
首先在您的应用程序类路径中包含Shiro Spring Web启动程序依赖项(我们建议使用Apache Maven或Gradle之类的工具来管理此依赖项)。
Shiro官方提供的自动化配置需要使用以下这种依赖
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-spring-boot-web-starter</artifactId>
<version>1.7.0</version>
</dependency>