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

...

Spring Boot Auto Configuration

Spring Boot 自动添加了 Spring Security,它要求所有请求都经过认证。它还会生成一个带有随机生成密码的用户,该密码已记录到可用于使用表单或基本认证来进行认证的控制台。