博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SpringBoot | 加入shiro之后如何优雅的访问默认目录static下的静态资源
阅读量:4183 次
发布时间:2019-05-26

本文共 1415 字,大约阅读时间需要 4 分钟。

一、shiro路径拦截配置

// TODO 重中之重啊,过滤顺序一定要根据自己需要排序        Map
filterChainDefinitionMap = new LinkedHashMap<>(); // 需要验证的写 authc 不需要的写 anon filterChainDefinitionMap.put("/resources/**", "anon"); //static开头的url可以匿名访问 filterChainDefinitionMap.put("/static/**", "anon"); filterChainDefinitionMap.put("/install", "anon"); filterChainDefinitionMap.put("/hello", "anon"); // anon:它对应的过滤器里面是空的,什么都没做 log.info("##################从数据库读取权限规则,加载到shiroFilter中##################"); // 不用注解也可以通过 API 方式加载权限规则 Map
permissions = new LinkedHashMap<>(); permissions.put("/users/find", "perms[user:find]"); filterChainDefinitionMap.putAll(permissions); //所有url都必须认证通过才可以访问 filterChainDefinitionMap.put("/**", "authc");

二、设置url默认访问的静态资源路径

@Configurationpublic class WebMvcConfig implements WebMvcConfigurer {    /**     * @author xiaobu     * @date 2019/1/18 13:51     * @param registry  registry     * @descprition  等价于 http://localhost:9001/1.txt 依次在static upload目录下找1.txt文件     * @version 1.0     */    @Override    public void addResourceHandlers(ResourceHandlerRegistry registry) {        registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");    }}

由于/**被shiro拦截只有通过static开头的url来访问static如:下的静态资源文件

转载地址:http://cfgai.baihongyu.com/

你可能感兴趣的文章
htmlunit爬取js异步加载后的页面
查看>>
修改Linux系统locale设置
查看>>
linux网络无法连接问题
查看>>
linux 查看ip
查看>>
go中map与xml互转
查看>>
java进程占用CPU过高
查看>>
CSDN-markdown编辑器
查看>>
拷贝整个目录到另一台服务器并排除log目录
查看>>
拜托,面试别再问我跳表了!
查看>>
android ArrayList<String> 转 String[]
查看>>
RecyclerView baseadapter
查看>>
Android中应用程序如何获得系统签名权限
查看>>
Recycler表格(excelPanel)
查看>>
android一行代码实现沉浸式布局效果
查看>>
json, recyclerView问题
查看>>
cmake处理多源文件目录的方法
查看>>
Service Intent must be explicit
查看>>
android studio SDK开发
查看>>
studio 统计代码的行数
查看>>
字符数组和16进制互换
查看>>