spring启动静态资源404错误
spring boot static resource 404 error
正在研究spring引导。
现在我必须将我的静态资源部署到 web 项目,链接它,
但它 returns 404 错误
此外,当我访问 "localhost:8080/appie/resources/js/common.js" 浏览器 returns 404 错误(我的上下文路径是 /appie)。
可能是什么原因?
server.contextPath=/appie
Spring 按照惯例引导在 src/main/resources/static
下提供静态资源。
资源的路径将与此相关,因此如果您将 common.js
放在 static
资源下,您将能够在以下位置访问它:
localhost:8080/appie/common.js
要以 resources/js/common.js
的形式访问它,请在 static
下创建此文件夹结构。
你应该阅读 this guide about serving static content with spring boot。
内容如下:
Spring Boot will automatically add static web resources located within any of the following directories:
- /META-INF/resources/
- /资源/
- /静态/
- /public/
将您的 js 文件放入其中一个目录后,您可以通过 $host:$port/$contextPath/common.js
访问它
正在研究spring引导。 现在我必须将我的静态资源部署到 web 项目,链接它, 但它 returns 404 错误
此外,当我访问 "localhost:8080/appie/resources/js/common.js" 浏览器 returns 404 错误(我的上下文路径是 /appie)。
可能是什么原因?
server.contextPath=/appie
Spring 按照惯例引导在 src/main/resources/static
下提供静态资源。
资源的路径将与此相关,因此如果您将 common.js
放在 static
资源下,您将能够在以下位置访问它:
localhost:8080/appie/common.js
要以 resources/js/common.js
的形式访问它,请在 static
下创建此文件夹结构。
你应该阅读 this guide about serving static content with spring boot。
内容如下:
Spring Boot will automatically add static web resources located within any of the following directories:
- /META-INF/resources/
- /资源/
- /静态/
- /public/
将您的 js 文件放入其中一个目录后,您可以通过 $host:$port/$contextPath/common.js
访问它