Springboot整合shiro时静态资源被拦截的问题

目录结构如下

Springboot整合shiro时静态资源被拦截的问题

在自己配置的ShiroConfig中已经放行了

filterChainDefinitionMap.put("/static/**", "anon");

login.ftl也引用了静态资源

<link rel="stylesheet" type="text/css" href="/logins/css/normalize.css" />
<link rel="stylesheet" type="text/css" href="/logins/css/demo.css" />
<link rel="stylesheet" href="/logins/js/vendor/jgrowl/css/jquery.jgrowl.min.css">

可是资源依然被拦截了

于是注释掉了

//filterChainDefinitionMap.put("/**", "authc");

静态资源可以访问了, 说明不是shiro的内在问题.

经过一番考虑, 感觉像是静态资源路径的问题, 于是在浏览器控制台看一下source的路径, 发现静态资源的路径前面是没有static的, 因而shiro也不会放行.

springboot默认会将static目录中的内容做为classes根目录的内容发布到web服务器, 所以如果想要放行静态资源, 同时又要实现拦截/**请求, 那么我的解决办法是:

解决办法

目录改造如下:

Springboot整合shiro时静态资源被拦截的问题

拦截配置:

filterChainDefinitionMap.put("/statics/**", "anon");
filterChainDefinitionMap.put("/**", "authc");

重启web服务器, 清除浏览器缓存, 此时source中已经是正确的路径了, 静态资源被引用了.问题解决

Springboot整合shiro时静态资源被拦截的问题


记录一下自己犯得低级错误, 见笑见笑 (笑哭脸)