pch205090 2021-12-31 10:19 采纳率: 100%
浏览 111
已结题

springboot整合springsecurity 自定义登录界面 静态资源被重定向

使用springboot整合springsecurity自定义登录界面 发现自定义界面的静态资源没加载进来 浏览器报302

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

@Autowired
private LoginUserDetailsService LUDS;
@Override
protected void configure(HttpSecurity http) throws Exception {
    http
            .authorizeRequests()
            .antMatchers("/css/**,/js/**,/img/**").permitAll()
            .anyRequest().authenticated()
            .and()
            .formLogin()
            .loginPage("/login")
            .successForwardUrl("/main_home")
            .permitAll().and().csrf().disable();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
    auth.userDetailsService(LUDS).passwordEncoder(password());
}

@Bean
PasswordEncoder password(){
    return new BCryptPasswordEncoder();
}

}

浏览器控制台报错代码
login:1 Refused to apply style from 'http://localhost:25080/login' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
login:1 Refused to apply style from 'http://localhost:25080/login' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
login:1 Refused to execute script from 'http://localhost:25080/login' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
login:1 Refused to execute script from 'http://localhost:25080/login' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
login:1 Refused to execute script from 'http://localhost:25080/login' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
login:1 Refused to apply style from 'http://localhost:25080/login' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
login:1 Refused to apply style from 'http://localhost:25080/login' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
出错代码302

  • 写回答

3条回答 默认 最新

  • CSDN专家-微编程 2021-12-31 10:56
    关注

    不是你这样写的呀,你要对每个静态资源分开写,然后逗号隔开,你这样写人家识别不了的

    img


    正确如下

    .antMatchers("/css/**","/js/**","/images/**").permitAll()
    

    如有帮助,望采纳一下,谢谢

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
  • 关注

    静态资源css,js,img等文件夹移到WEB-INF外面即可。

    评论
  • a1767028198 2021-12-31 15:50
    关注

    静态资源放行走configure(WebSecurity web) 这个方法

    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 1月9日
  • 已采纳回答 1月1日
  • 创建了问题 12月31日

悬赏问题

  • ¥15 Java环境配了,但启用不成功。
  • ¥15 求一个智能家居控制的代码
  • ¥15 ad软件 pcb布线pcb规则约束编辑器where the object matpcb布线pcb规则约束编辑器where the object matchs怎么没有+15v只有no net
  • ¥15 虚拟机vmnet8 nat模式可以ping通主机,主机也能ping通虚拟机,但是vmnet8一直未识别怎么解决,其次诊断结果就是默认网关不可用
  • ¥20 求各位能用我能理解的话回答超级简单的一些问题
  • ¥15 yolov5双目识别输出坐标代码报错
  • ¥15 这个代码有什么语法错误
  • ¥15 给予STM32按键中断与串口通信
  • ¥15 使用QT实现can通信
  • ¥15 关于sp验证的一些东西,求告知如何解决,