WebFlux 應用入門
更新依賴
透過新增 spring-boot-starter-security
,您可以將 Spring Security 新增到您的 Spring Boot 專案中。
-
Maven
-
Gradle
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
implementation 'org.springframework.boot:spring-boot-starter-security'
啟動 Hello Spring Security Boot
您現在可以透過使用 Maven 外掛的 run
目標來執行 Spring Boot 應用。以下示例展示瞭如何操作(以及操作後的輸出開頭)
執行 Spring Boot 應用
-
Maven
-
Gradle
$ ./mvnw spring-boot:run
...
INFO 23689 --- [ restartedMain] .s.s.UserDetailsServiceAutoConfiguration :
Using generated security password: 8e557245-73e2-4286-969a-ff57fe326336
...
$ ./gradlew bootRun
...
INFO 23689 --- [ restartedMain] .s.s.UserDetailsServiceAutoConfiguration :
Using generated security password: 8e557245-73e2-4286-969a-ff57fe326336
...
認證
您可以訪問應用地址 localhost:8080/,瀏覽器將被重定向到預設登入頁面。您可以使用預設使用者名稱 user
以及日誌中隨機生成的密碼進行登入。然後瀏覽器將跳轉到最初請求的頁面。
要登出,您可以訪問 localhost:8080/logout,然後確認您希望登出。