配置
代码地址:https://github.com/uzck/spring-security-login-demo
只是一个小的验证登录的demo,按照网上的版本来莫名踩坑,不清楚是不是Spring版本的问题,声明下自己的配置,这是必须的两个包,数据库配置按照自己需要的来。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<version>2.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.1.1.RELEASE</version>
</dependency>
在pom.xml的build中添加这部分,保证resource里的资源在打包的时候都被包括进来
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.yml</include>
<include>**/*.ftl</include>
<include>**/*.html</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
application.yml
这里具体的配置还是按照自己的工程来修改
spring:
datasource:
username: uzck
password: 123456
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/todo?useUnicode=true&characterEncoding=UTF-8
freemarker:
charset: UTF-8
cache: false
template-loader-path: classpath:/templates/
suffix: .ftl
mybatis:
type-aliases-package: security/dao
mapper-locations: classpath:mapper/*.xml
数据表
CREATE TABLE `user` (
`username` varchar(255) NOT NULL,
`password` char(255) NOT NULL,
`roles` enum('MEMBER','MEMBER,LEADER','SUPER_ADMIN') NOT NULL DEFAULT 'MEMBER',
PRIMARY KEY (`username`),
KEY `username` (`username`)
) ENGINE=InnoDB DEFAULT

这篇博客介绍了如何在Spring Boot项目中整合Spring Security实现用户登录验证。作者分享了一个简单的登录验证Demo,包括配置、数据库表、Spring Security配置、UserDetailService、UserController、模板文件以及Mybatis的相关操作。在实际操作中遇到了HTTP 403错误和登录循环跳转的问题,通过查阅资料和调整配置最终解决了问题。

662

被折叠的 条评论
为什么被折叠?



