理解springboot中的静态资源目录位置

理解springboot中的静态资源目录位置

springboot的静态资源目录如下
/static(或/public ,/resources,/META-INF/resources)

By default, Spring Boot serves static content from a directory called /static (or /public or /resources or /META-INF/resources) in the classpath or from the root of the ServletContext. It uses the ResourceHttpRequestHandler from Spring MVC so that you can modify that behavior by adding your own WebMvcConfigurer and overriding the addResourceHandlers method.

正确的理解上述的资源目录在根目录下的意思
也就是上述的文件夹的内容在编译后都放置在/目录下。
比如说你的/public/css/style.css文件,在项目启动后他的位置应该为:/css/style.css

classpath 是一个表示去告诉java在哪里去获取对应的类和包的路径标识。也就是我们常说的项目根路径。

猜你喜欢

转载自blog.csdn.net/xl_1851252/article/details/81544628