Spring Boot with Security不提供我的静态内容

问题描述 投票:0回答:1

嗨这里是我的安全配置文件,我正在使用Spring Boot 2.0.6.RELEASE和我的静态内容文件只在静态文件夹中static-> css,js,images,fonts

我已经尝试了所有其他帖子解决方案,但没有一个为我工作,仍然静态内容是安全的样式没有得到应用等提前感谢

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    private final String[] PUBLIC_MATCHER = {"/css/**","/js/**","/fonts/**","/images/**", "/"};

    @Override
    protected void configure(HttpSecurity http) throws Exception {

        http
            .authorizeRequests()
            .antMatchers(PUBLIC_MATCHER)
            .permitAll().anyRequest().authenticated()
            .and()
            .csrf().disable().cors().disable()
            .formLogin().failureUrl("/login?error").defaultSuccessUrl("/dashboard")
            .loginPage("/login").permitAll()
            .and()
            .logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
            .logoutSuccessUrl("/?logout").deleteCookies("remember-me").permitAll()
            .and()
            .rememberMe();

       }
    }
 }
java spring-boot spring-security
1个回答
0
投票

在安全配置文件中添加此方法,希望它可以工作

//this method allows static resources to be neglected by spring security
        @Override
        public void configure(WebSecurity web) throws Exception {
            web
                .ignoring()
                .antMatchers("/resources/**", "/static/**","/css/**","/js/**","/fonts/**","/images/**");
        }
© www.soinside.com 2019 - 2024. All rights reserved.