Getting Started with WebFlux Applications
此部分涵盖了有关如何在响应式应用程序中将 Spring Security 与 Spring Boot 配合使用的最低设置。
可在https://github.com/spring-projects/spring-security-samples/tree/{gh-tag}/reactive/webflux/java/hello-security[我们的样例库]中找到已完成的应用程序。您可通过 clicking here下载一个最小的Reactive Spring Boot + Spring Security应用程序以供方便。 |
Updating Dependencies
你可以通过添加 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'
Starting Hello Spring Security Boot
您现在可以使用Maven插件的`run`目标 run the Spring Boot application 。以下示例演示如何执行此操作(以及执行此操作后输出的开头):
Running Spring Boot Application
-
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
...
Authenticating
您可以访问[role="bare"][role="bare"]http://localhost:8080/应用程序,该应用程序将把浏览器重定向到默认登录页面。您可以提供`user`默认用户名和记录到控制台的随机生成的密码。然后浏览器将转到最初请求的页面。
要注销,您可以访问[role="bare"][role="bare"]http://localhost:8080/logout,然后确认您希望注销。