开发时临时关闭配置好的SpingSecurity服务的解决办法

时间:2025-04-11 13:20:59

以下提供两种解决方案:

(1)1.直接通过不走springsecurity过滤连的方式放行全部url

重写WebSecurityConfigurerAdapter的configure(WebSecurity web)方法

  @Override
    public void configure(WebSecurity web) throws Exception {
        //不走Spring SEcurity的过滤器链,也就意味着不会将用户的信息记录在session中,因此尽量不要用这种方式进行资源放行
        //关闭springsecurity服务
      web.ignoring().antMatchers("/**");
    }

(2) 2.第二种方式需要两步操作

2.1给springboot主方法中的注解去除如下类

@SpringBootApplication(exclude = {  })

2.2 注释掉springsecurity配置类的@EnableWebSecurity注解