I want to create a @SpringBootTest that makes use of my full configuration structure.
Problem: I'm creating an @Bean SecurityWebFilterChain that requires a ServerHttpSecurity, which is somehow missing in a test:
@SpringBootApplication
public class MainApp { ... }
//for simple testing I started with anonymous auth
@Configuration
public class ReactiveSecurityConfiguration {
@Bean
public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {
return http.anonymous()
.and().csrf().disable()
.build();
}
}
@SpringBootTest
public class TestClass {
@Test
public void test() {
}
}
Result:
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'securityWebFilterChain' defined in class path resource [ReactiveSecurityConfiguration.class]:
Unsatisfied dependency expressed through method 'securityWebFilterChain' parameter 0;
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException:
No qualifying bean of type 'org.springframework.security.config.web.server.ServerHttpSecurity' available:
expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
Update
I discovered if I add the following annotations to my Test Class, the testmethod works without errors. But is that intentional?
@EnableWebFlux
@EnableWebFluxSecurity
@SpringBootTest
public class TestClass { }