1. 創(chuàng)建DEMO文件
pom.xml文件
<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>
controller
@RestController
@RequestMapping(value = "/demo")
public class HelloController {
@RequestMapping(value = "/hello")
public String hello() {
System.out.println("我愛蛋炒飯");
return "hello";
}
}
啟動項目,會在控制臺輸出類似如下的信息
Using generated security password: a2748340-499c-4f27-a440-77b64b022374
這個是初始密碼,賬號是user。使用這個就可以完成登錄認證
在頁面中輸入啟動信息localhost:xxxx/xxx/demo/hello輸入賬號密碼就可以完成登錄
也可以在application中配置基礎的賬號密碼,這樣就可以使用者配置的進行登錄了
spring:
security:
user:
name: coderymy
password: 123