Springboot Junit 至少一个SecurityBuilder<? extends SecurityFilterChain> needs to be specified 错误

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

Springboot 2.5.13(安全开启),Junit5:

错误:至少有一个 SecurityBuilder 需要指定。通常,这是通过公开 SecurityFilterChain bean 或通过添加扩展 WebSecurityConfigurerAdapter 的 @Configuration 来完成的。更高级的用户可以直接调用WebSecurity.addSecurityFilterChainBuilder

解决方案:禁用安全性:在 /tests 文件夹中,为 WebSecurityConfigurerAdapter 创建一个 @Configuration 以允许所有请求:

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