springboot 整合 shiro (Web Applications)避坑一 ,请看shiro官网

导读:本篇文章讲解 springboot 整合 shiro (Web Applications)避坑一 ,请看shiro官网,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com

避坑一

异常打印

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官网的解释

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>

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/69749.html

(0)
小半的头像小半

相关推荐

极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!