在本文中,我们将探讨Spring Security 5框架的新特性,以保护被动应用程序。此释放装置与Spring5和Spring Boot2对齐。
在本文中,我们将不深入讨论反应式应用程序本身的细节,这是Spring5框架的一个新特性。
Maven设置
我们将使用springbootstarters来引导我们的项目以及所有必需的依赖项。
基本设置需要父声明、web启动程序和安全启动程序依赖项。我们还需要Spring Security测试框架:
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.4.0</version> <relativePath/> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-webflux</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-test</artifactId> <scope>test</scope> </dependency> </dependencies>
我们可以在Maven Central查看当前版本的Spring Boot security starter。
项目设置
应式应用程序引导反
我们不使用标准的 @SpringBootApplication
配置,而是配置一个基于Netty的web服务器。NETY是一个异步的基于NIO的框架,它是无功应用的良好基础。
@EnableWebFlux
注释启用应用程序的标准Spring-Web响应式配置:
@ComponentScan(basePackages = {"com.baeldung.security"}) @EnableWebFlux public class SpringSecurity5Application { public static void main(String[] args) { try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(