基于Spring Security5的响应式应用

在本文中,我们将探讨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(
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值