springboot thymeleaf 返回html 404_SpringBoot+SpringSecurity+Thymeleaf认证失败返回错误踩坑记录...

本文记录了在SpringBoot应用中整合SpringSecurity和Thymeleaf时,处理登录失败返回404的问题。通过分析SpringSecurity的过滤器流程和异常处理,了解到错误信息存储在session中,但直接通过Thymeleaf取值失败。解决方案来自StackOverflow,注意Thymeleaf中引用session变量的正确方式。此外,文中还提及了SpringSecurity的常见登录异常类型及其定制化提示。
摘要由CSDN通过智能技术生成

现在企业开发追求快速,Springboot以多种优秀特性引领潮流,在众多使用SpringBoot的企业中,因为SpringSecurity安全框架由于其与spring框架无缝衔接等优秀特性被使用,这里记录一下使用这两个框架以及Thymeleaf模板过程中遇到的一些坑

如果想学习Java工程化、高性能及分布式、深入浅出。微服务、Spring,MyBatis,Netty源码分析的朋友可以加我的Java高级交流:854630135,群里有阿里大牛直播讲解技术,以及Java大型互联网技术的视频免费分享给大家。

本人环境:

OS:windows 10

JDK:1.8

IDE:Intellij idea

SpringBoot:1.5.16

SpringSecurity:4.2.8

thymeleaf:3.0.9

初学阶段,我们大都使用表单提交来进行登录,这里我们也采用这种方式

444e23c07a021cb1ae8b5ab80aa7b93d.png

表单设计大都大同小异,这里就不过多赘述,接下来我们看下后台SpringSecurity的配置

eb3f24ebcb7de74c0352bc1e0c1b018f.png
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
```xml <!-- Spring Boot Starter Parent --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.5.2</version> <relativePath/> <!-- lookup parent from repository --> </parent> <!-- Spring Boot Starter Web --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- Spring Security --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> <!-- Thymeleaf --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <!-- Thymeleaf Spring Security --> <dependency> <groupId>org.thymeleaf.extras</groupId> <artifactId>thymeleaf-extras-springsecurity5</artifactId> </dependency> <!-- Spring Boot Starter Test --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> ``` 注释说明: 1. Spring Boot Starter Parent:Spring Boot 的父级依赖,定义了 Spring Boot 的版本和依赖管理。 2. Spring Boot Starter Web:Spring Boot Web 组件的依赖,包含了 Spring MVC、Tomcat 等。 3. Spring SecuritySpring Security 组件的依赖,提供了安全认证和授权功能。 4. ThymeleafThymeleaf 模板引擎的依赖,用于生成 HTML 页面。 5. Thymeleaf Spring SecurityThymeleafSpring Security 集成的依赖,提供了 Thymeleaf 中使用 Spring Security 的标签和属性。 6. Spring Boot Starter Test:Spring Boot 测试组件的依赖,包含了 JUnit、Mockito 等。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值