Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ClassNotFoundException with Spring WebFlux Security

I'm having the following problem:

I am trying to setup a basic Spring Boot (2.0.0.M2) Project containing Spring Webflux and Spring Security.

My pom.xml looks like this (generated via 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 {}

I am not getting any further because I get an exception on startup:

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

So I figure that the whole org.springframework.security.web.server package is not on the classpath, although it should be there, since it is included in the API docs.

Seems like I am doing something wrong, but I don't know what.

like image 567
Roen Avatar asked Sep 01 '25 01:09

Roen


1 Answers

Currently Spring Boot's spring-boot-starter-security does not include spring-security-webflux.

Add it as project dependency explicitly.

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

See this issue : Provide auto-configuration for WebFlux-based security.

BTW, check my working codes: https://github.com/hantsy/spring-reactive-sample/tree/master/boot

Updated: In Spring Boot 2.0.0.RELEASE, spring-boot-starter-security includes webflux support.

like image 79
Hantsy Avatar answered Sep 02 '25 19:09

Hantsy