在继承WebSecurityConfigurerAdapter的这个配置类中,重写configure的这个方法,直接把static下的所有静态资源全部放行
//这里是放行静态资源的
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/static/**");
}
这个重写的configure的方法里也可以放行静态资源,也能放行路径antMatchers这个地方
@Override
protected void configure(HttpSecurity http) throws Exception {
//表单登录
http.formLogin()
.loginPage("/page/login.html") //登录页面设置
.loginProcessingUrl("/login") //登录访问的路径
.defaultSuccessUrl("/main") //登录成功后,跳转路径
.permitAll()
.and().authorizeRequests() //开启登录选择认证
.antMatchers("/static/**").permitAll() //设置哪些路径不需要认证,这里也能放行静态资源
.anyRequest().authenticated() //表示剩余其他接口,登录之后就能访问
.and().csrf().disable(); //关闭csrf防护
}