首页 文章

spring boot静态资源404错误

提问于
浏览
-1

我正在研究 Spring 季靴子 . 现在我必须将我的静态资源部署到Web项目,并将其链接,但它会返回404错误

enter image description here

此外,当我访问“localhost:8080 / appie / resources / js / common.js”浏览器返回404错误(我的上下文路径是/ appie) .

那可能是什么原因?

server.contextPath=/appie

2 回答

  • 0

    按照约定,Spring Boot在 src/main/resources/static 下提供静态资源 . 资源的路径将相对于此,因此如果您将 common.js 放在 static 资源下,您将能够访问:localhost:8080 / appie / common.js

    要在 resources/js/common.js 中访问它,请在 static 下创建此文件夹结构 .

  • 1

    你应该阅读this guide about serving static content with spring boot .

    它说如下:

    Spring Boot将自动添加位于以下任何目录中的静态Web资源:

    • / META-INF /资源/

    • / resources /

    • / static /

    • / public /

    将js文件放在其中一个目录后,您可以通过$ host:$ port / $ contextPath / common.js访问它

相关问题