我正在研究弹簧靴。现在我必须将我的静态资源部署到 web 项目,链接它,但它返回 404 错误
此外,当我访问“localhost:8080/appie/resources/js/common.js”时,浏览器返回 404 错误(我的上下文路径是 /appie)。
那可能是什么原因?
server.contextPath=/appie
我正在研究弹簧靴。现在我必须将我的静态资源部署到 web 项目,链接它,但它返回 404 错误
此外,当我访问“localhost:8080/appie/resources/js/common.js”时,浏览器返回 404 错误(我的上下文路径是 /appie)。
那可能是什么原因?
server.contextPath=/appie
Spring Boot 按照惯例在src/main/resources/static
. 资源的路径是相对于这个的,所以如果你把它放在common.js
资源下static
,你将能够访问它:localhost:8080/appie/common.js
要访问它,请resources/js/common.js
在下创建此文件夹结构static
。
您应该阅读有关使用 spring boot 提供静态内容的指南。
它说:
Spring Boot 将自动添加位于以下任何目录中的静态 Web 资源:
将 js 文件放在此目录之一后,您可以通过 $host:$port/$contextPath/common.js 访问它