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

避坑一

异常打印

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>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值