我现在正在学习 Spring 天 . 我正在使用 spring 靴和百日咳模板 . 我做了spring docs中提供的spring安全性示例 . 现在我想在我的应用程序中包含js文件来实现记住我的功能,所以我在 src/main/resources/js 文件夹中添加了 app.js 文件 . 我的login.html位于src / main / resources / templates文件夹中 . 我包括在内

type="text/javascript" src="/js/app.js"

在我的html文件中 . 我也尝试将js放在同一个文件夹中,并在 src/main/resources/static/js 中,并在我的html中包含

type="text/javascript" src="./js/app.js"

. 但是对于所有情况,浏览器都在抛出 "Refused to execute script from 'http://localhost:8080/js/app.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled." 错误 . 我用谷歌搜索同样的,我没有得到任何正确的答案 . Spring 天和百里香的新手 . 请帮助我 . 谢谢 . 当我输入登录详细信息并按登录时,浏览器正在显示我的app.js内容

IT GOT SOLVED the error was appearing because of spring security issue. since I was not logged in, spring security was not allowing me to access js file. so i added that URL in spring security permitAll(). it got solved