Search code examples
spring-bootjunit5spring-boot-test

Springboot Junit At least one SecurityBuilder<? extends SecurityFilterChain> needs to be specified error


Springboot 2.5.13 (with security on), Junit5:

Error: At least one SecurityBuilder<? extends SecurityFilterChain> needs to be specified. Typically this is done by exposing a SecurityFilterChain bean or by adding a @Configuration that extends WebSecurityConfigurerAdapter. More advanced users can invoke WebSecurity.addSecurityFilterChainBuilder directly


Solution

  • Solution: Disable security: in /tests folder, create a @Configuration for the WebSecurityConfigurerAdapter to allow all the requests:

    @Configuration
    @Order(1)
    public class ApplicationSecurity extends WebSecurityConfigurerAdapter {
      @Override
      public void configure(WebSecurity web) throws Exception {
        web.ignoring().antMatchers("/**");
      }
    }