配置
代码地址: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 C