具有 Spring WebFlux 安全性的 ClassNotFoundException

ClassNotFoundException with Spring WebFlux Security

我遇到了以下问题:

我正在尝试设置一个基本的 Spring 引导 (2.0.0.M2) 项目,其中包含 Spring Webflux 和 Spring 安全性。

我的 pom.xml 看起来像这样(通过 start.spring.io 生成):

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.0.M2</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<dependencies>
    ...
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-webflux</artifactId>
    </dependency>
    ...
</dependencies>

Spring安全配置:

@EnableWebFluxSecurity
public class SecurityConfig extends WebFluxSecurityConfiguration {}

我没有进一步了解,因为我在启动时遇到异常:

Caused by: java.lang.ClassNotFoundException: org.springframework.security.web.server.context.SecurityContextRepository

所以我认为整个 org.springframework.security.web.server 包不在类路径中,尽管它应该在那里,因为它包含在 API docs.

好像我做错了什么,但我不知道是什么。

当前 Spring 引导的 spring-boot-starter-security 不包括 spring-security-webflux

将其显式添加为项目依赖项。

<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-webflux</artifactId>
</dependency>

看到这个issue : Provide auto-configuration for WebFlux-based security

顺便说一句,检查我的工作代码:https://github.com/hantsy/spring-reactive-sample/tree/master/boot

已更新:在 Spring Boot 2.0 中。0.RELEASE,spring-boot-starter-security 包括 webflux 支持。