如何让spring安全允许访问静态资源?

How to make spring security permit access to static resources?

我决定向我的应用程序添加一些 css,但由于 spring 安全性,它无法正常工作。这是我试图解决的问题。 1) 添加到 mvcConfig

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry
            .addResourceHandler("/resources/**")
            .addResourceLocations("/resources/");
}

2) 将此添加到 webSecurityConfig

 @Override
public void configure(WebSecurity web) throws Exception {
    web
            .ignoring()
            .antMatchers("/resources/**");
}

3)我也有这个方法

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.csrf().disable()
            .authorizeRequests()
            .antMatchers("/","/registration","/resources/**").permitAll()
            .anyRequest().authenticated()
            .and()
            .formLogin()
            .loginPage("/login")
            .permitAll()
            .and()
            .logout()
            .permitAll();
}
  1. 我也将此添加到 application.properties 文件中: spring.mvc.static-path-pattern=/resources/**

none 这些方法对我有用。如果有人处理过这个,请帮忙

如果对您有帮助,您可以查看整个项目my project

p.s。我只是 spring 的初学者,所以不要评判我

您也必须忽略 css 目录。

@Component
public class SecurityConfig implements WebSecurityConfigurer {

    @Override
    public void configure(WebSecurity web) {
        web
            .ignoring() 
                .antMatchers("/css/**")
                .antMatchers("/js/**")
                .antMatchers("/images/**")
                .antMatchers("/resources/**");
    }
}