Spring Boot 2 Shiro 去掉URL jsessionid

位置:首页>文章>详情   分类: 教程分享 > Java教程   阅读(7407)   2023-03-28 11:29:14

一、项目环境

  1. Spring Boot 2.1.2.RELEASE
  2. shiro-spring 1.4

二、去掉URL jsessionid

在shiro配置中,配置关闭url中显示sessionId
    @Bean
    public DefaultWebSessionManager sessionManager() {
        DefaultWebSessionManager sessionManager = new DefaultWebSessionManager();
        // 去掉shiro登录时url里的JSESSIONID
        sessionManager.setSessionIdUrlRewritingEnabled(false);
        if ("redis".equals(cacheType)){
            sessionManager.setCacheManager(shiroRedisCacheManager());
            Log.info("当前Shiro缓存框架为:redis",getClass());
        }else if ("ehcache".equals(cacheType)){
            sessionManager.setCacheManager(shiroEhCacheManager());
            Log.info("当前Shiro缓存框架为:ehcache",getClass());
        }else{
            throw new RuntimeException("缓存类型值应该为:redis|ehcache;当前输入值:" + cacheType);
        }
        return sessionManager;
    }
核心代码:
sessionManager.setSessionIdUrlRewritingEnabled(false);
以上片段代码关闭了URL中带SESSIONID

三、其他注意事项

通过上方得配置,常规得URL后面是不会跟sessionId了,但是thymeleaf模板中,如果有以下写
<link rel="stylesheet" th:href="@{/assets/framework/bootstrap/dist/css/bootstrap.min.css}"/>
在加载这个资源文件得时候同样会带出sessionid,可能会引起首次打开网页CDN加载失败,刷新一次恢复正常。

简单得说就是在使用CDN得情况下,thymeleaf模板引擎标准引入资源文件会首次失败得情况(亲测)
CDN加载失败

目前我的解决办法是直接普通写法:
<link rel="stylesheet" href="/assets/framework/bootstrap/dist/css/bootstrap.min.css"/>

如果有更合理得解决办法请告诉我,谢谢。


 
标签: shiro thymeleaf
地址:https://www.leftso.com/article/757.html

相关阅读

一、项目环境Spring Boot 2.1.2.RELEASEshiro-spring 1.4二、去掉URL jsessionid在shiro配置中,配置关闭url中显示sessionId ...
Apache Shiro教程,您的第一个Apache Shiro应用程序(翻译)-编程技术
一、spring boot shiro 无状态token认证项目结构图​二、无状态spring boot shiro相关配置2.1shiro redis 缓存配置首先是实现shiro的cache...
SSH/SSM项目中如何集成thymeleaf?本文将讲解SSH/SSM项目中如何集成thymeleaf模板引擎
Thymeleaf 递归,Thymeleaf模板引擎递归展示如评论留言等场合适用
组态,将Shiro集成到任何Web应用程序中的最简单的方法是在web.xml中配置Servlet ContextListener和Filter,了解如何读取Shiro的INI配置。
本文说一下在thymeleaf模板引擎中,如何给 textarea 赋值
Java编程之spring boot shiro redis整合基于角色和权限的安全管理,Java编程,spring boot,shiro,权限控制
thymeleaf模板 报错信息:​​​​​​​org.thymeleaf.exceptions.TemplateInputException: Error resolving template...