In a Spring Boot project using Spring Modulith
to structure the application.
When I add a subdir "config" with a bean definition, the app refuses to start. The file looks like this:
@Configuration
@EnableWebFluxSecurity
public class WebSecurityConfig {
@Bean
public SecurityWebFilterChain registerAuthenticationFilter(
ServerHttpSecurity httpSecurity) {
....
I get error when starting the app:
Error creating bean with name ...
Unsatisfied dependency expressed through method 'setSecurityWebFilterChains' parameter 0:
Error creating bean with name 'registerAuthenticationFilter' defined in class path resource
Failed to instantiate [org.springframework.security.web.server.SecurityWebFilterChain]: Illegal arguments to factory method
'registerAuthenticationFilter'; args: org.springframework.security.config.annotation.web.reactive.ServerHttpSecurityConfiguration$ContextAwareServerHttpSecurity@284bdeed
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.resolveMethodArguments(AutowiredAnnotationBeanPostProcessor.java:875) ~
When I put the file with the config bean in the root directory, then it the apps starts just fine.
The project strucuture looks like this:
/root
application.java
/config
WebSecurityConfig.java <- this one is the problem
/moduleA
/moduleB
But when I have more config beans, and a lot of them are cross-cutting, I would like to put them in a own config directory. This seem to contradict the normal modulith convention. How do I organize the config beans when using Spring Modulith?
It is Java 20
and Spring Boot 3.1.4