应用程序受到保护后无法访问静态文件

时间:2017-02-06 17:09:41

标签: java css spring-boot

出于某种原因,我无法访问我的CSS和JS文件。发生了什么事?

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
            .authorizeRequests()
            .antMatchers("/", "/home").permitAll()
            .anyRequest().authenticated()
            .and()
            .formLogin()
            .loginPage("/login")
            .permitAll()
            .and()
            .logout()
            .permitAll().and().authorizeRequests().antMatchers("/static/**").permitAll();
}

1 个答案:

答案 0 :(得分:1)

尝试使用:

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
        .authorizeRequests()
            .antMatchers("/", "/home").permitAll()
            .antMatchers("/static/**").permitAll()
            .anyRequest().authenticated()
            .and()
        .formLogin()
            .loginPage("/login")
            .permitAll()
            .and()
        .logout()
            .permitAll();
}

订单很重要。所有权限必须在.anyRequest()。authenticated()

之前