使用SpringBoot框架和SpringSecurity框架整合出现because its MIME type ('text/html') is not executable
前端页面出现:
Refused to execute script from ‘http://localhost:8080/login’ because its MIME type (‘text/html’) is not executable, and strict MIME type checking is enabled.
解决方法:
- 将静态资源的路径写在自定义的安全策略中
所以要找到对自定义的springSecurity安全框架的配置类进行修改
自定义的springSecurity安全框架的配置类,继承WebSecurityConfigurerAdapter,重写其中的方法configure
我们可以在authorizeRequests() 后定义多个antMatchers()配置器来控制不同的url接受不同权限的用户访问。
antMatchers在这里配置哪些页面或资源不需要认证:
- 如果此方法还会出现
Refused to execute script from ‘http://localhost:8080/login’ because its MIME type (‘text/html’) is not executable, and strict MIME type checking is enabled.
可对页面中的引用路径进行修改,有可能是页面中的资源路径没有引用到static下的静态资源。
例如:
在这个相对路径中,我的images文件夹在default下
由于前面少加一个文件夹的路径,就会导致Spring Security框架拦截了该资源的请求,
所以在前面加上default
问题就解决了
注意:该报错不会具体指出是哪一行出现错误,所以要细心检查前端引用资源的代码,也有可能是图片,js, css, 字体文件,音频,视频没有引用到static下的静态资源。
- 关于spring boot资源的存放
static 目录存放我们的web静态资源页面
templates 存放我们的html, jsp, ftl等各种格式网站页面