本次项目是基于Springboot
由于使用Security,因此必须有创建web工程
这边Security的就不多说了,自行百度
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
application.yml
server:
tomcat:
uri-encoding: UTF-8
port: 8080
servlet:
context-path: /security
springboot对于spring security提供了自动化的配置方案,可以使用更少的配置来使用Spring Security
因此直接写一个controller类来测试
package cn.sysu.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class TestController {
@GetMapping("/hello")
public String hello(){
return "Hello,SpringSecurity";
}
}
启动时,控制台会生成一个密码,同时默认的用户名时user
输入url,自动跳转到登陆页面,该页面也是Security帮我们弄好的
输入用户名和密码