Spring Boot 2 Shiro 去掉URL jsessionid

编程教程 > WEB > JavaScript (14726) 2024-11-26 14:39:04

一、项目环境

  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"/>

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


 

评论
User Image
提示:请评论与当前内容相关的回复,广告、推广或无关内容将被删除。

相关文章
一、项目环境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模板引擎递归展示如评论留言等场合适用
使用thymeleaf 模板创建时间 使用thymeleaf 创建指定日期为:2023-10-18 #dates.create(2023,10,18) 使用thymeleaf ...
组态,将Shiro集成到任何Web应用程序中的最简单的方法是在web.xml中配置Servlet ContextListener和Filter,了解如何读取Shiro的INI配置。
thymeleaf 设置不校验html标签
本文说一下在thymeleaf模板引擎中,如何给 textarea 赋值
某些情况需要在thymeleaf 模板文件中定义变量,使用参考 定义单个参数:&lt;!doctype html&gtl;&lt;html lang="zh" xmlns="htt
Java编程之spring boot shiro redis整合基于角色和权限的安全管理,Java编程,spring boot,shiro,权限控制
故事        今天遇到了一个问题,就是一个用户属于多个部门,之前的角色是挂在部门下的,也就说处理不同业务需要不同的部门,这里就暂时考虑了在线的用户角色切换,项目中使用的是shiro权限框架
thymeleaf模板 报错信息:​​​​​​​org.thymeleaf.exceptions.TemplateInputException: Error resolving template...
环境Thymeleaf 3.0循环5次需求:输出5个li编码参考:&lt;ul&gtl; &lt;li th:each="index:${#numbers.sequence(1,