1

我遇到以下问题:

我正在尝试设置一个包含 Spring Webflux 和 Spring Security 的基本 Spring Boot (2.0.0.M2) 项目。

我的 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>

弹簧安全配置:

@EnableWebFluxSecurity
public class SecurityConfig extends WebFluxSecurityConfiguration {}

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

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

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

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

4

1 回答 1

4

目前 Spring Bootspring-boot-starter-security不包括spring-security-webflux.

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

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

请参阅此问题:为基于 WebFlux 的安全性提供自动配置

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

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

于 2017-08-21T03:39:05.253 回答