springboot集成spring Security時前端出現Refused to execute script from 'http://localhost:8080/' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.問題
最近學習springSecurity,遇到很多坑,在此記錄一下,借此可以幫助更多的人
1. 出現情況

2. 原因分析
第一次是我以為是路徑問題,可是查看后發現路徑並未寫錯,springboot默認靜待資源映射是static目錄下,但是之前可以正常訪問,於是考慮是spring security問題,於是查看spring Security配置類添加忽略攔截文件
@Override
public void configure(WebSecurity web) throws Exception {
// 設置攔截忽略文件夾,可以對靜態資源放行
web.ignoring().antMatchers("/js/**", "/css/**","/images/**","/lib/**");
}
表示忽略攔截static目錄下指定路徑靜態文件,注意這里千萬不要使用"/**"。
3. 測試結果

發現控制台已經不再報錯,問題解決
4. 總結
如果使用"/**"如下面示例代碼:
@Override
public void configure(WebSecurity web) throws Exception {
// 設置攔截忽略文件夾,可以對靜態資源放行
web.ignoring().antMatchers("/**");
}
這樣會有大問題。因為WebSecurity是全局配置,如果配置"/**"會導致權限訪問問題這個看我后續博客會說明。
