【问题标题】:ClassNotFoundException with Spring WebFlux Security带有 Spring WebFlux 安全性的 ClassNotFoundException
【发布时间】:2017-12-20 09:01:05
【问题描述】:

我遇到以下问题:

我正在尝试设置一个包含 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>

SpringSecurityConfig:

@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 中。

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

【问题讨论】:

  • 你必须添加依赖。 Afaik 安全通量罐不是spring-boot-starter-security 东西的一部分。如果是尝试清除本地存储库并重新下载依赖项。
  • 你是对的,它不是其中的一部分。我期待它是因为它包含在 Spring Security 5.0.0.M2 API-docs 中。谢谢!
  • 那你能回答你自己的问题吗?这应该有助于社区中的其他开发人员。

标签: spring spring-boot spring-security spring-webflux


【解决方案1】:

目前 Spring Boot 的 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 支持。

【讨论】:

    猜你喜欢
    • 2020-11-18
    • 1970-01-01
    • 2021-06-23
    • 2019-02-05
    • 2019-01-27
    • 2020-10-09
    • 2015-03-18
    • 2023-03-31
    • 2020-03-20
    相关资源
    最近更新 更多