Spring Boot对静态资源的映射规则

规则一:所有 " /webjars/** " 请求都去classpath:/META-INF/resources/webjars/找资源

webjars:以jar包的方式引入静态资源

举例:引入jquery.js文件

pom.xml文件添加如下依赖:

<dependency>
    <groupId>org.webjars</groupId>
    <artifactId>jquery</artifactId>
    <version>3.4.1</version>
</dependency>

jar包目录如下所示:

访问localhost:8080/webjars/jquery/3.4.1/jquery.js即可获得文件。

规则二:" /** " 访问当前项目的任何资源,(静态资源的文件夹)

"classpath:/META-INF/resources/"
"classpath:/resources/"
"classpath:/static/"
"classpath:/public/"
"/":当前项目的根路径

如下图classpath下的对应文件夹,classpath是指java和resource

localhost:8080/abc === 去上面说明的几个文件夹中找abc

举例:访问static文件夹下的images/person.jpg

访问路径为:localhost:8080/images/person.jpg

规则三:欢迎页为静态资源文件夹下的所有index.html页面,被 " /** " 映射

如:localhost:8080/

规则四:所有 " **/favicon.icon "都是在静态资源文件夹下查找,用于设置网页图标

原文地址:https://www.cnblogs.com/YeHuan/p/12103766.html

时间: 2024-08-01 01:27:51

Spring Boot对静态资源的映射规则的相关文章

Spring boot 默认静态资源路径与手动配置访问路径的方法

这篇文章主要介绍了Spring boot 默认静态资源路径与手动配置访问路径的方法,非常不错,具有参考借鉴价值,需要的朋友可以参考下 在application.propertis中配置 ##端口号 server.port=8081 ##默认前缀 spring.mvc.view.prefix=/ ## 响应页面默认后缀 spring.mvc.view.suffix=.html # 默认值为 /** spring.mvc.static-path-pattern=/** # 这里设置要指向的路径,多个

Spring Boot 的静态资源处理

做web开发的时候,我们往往会有很多静态资源,如html.图片.css等.那如何向前端返回静态资源呢?以前做过web开发的同学应该知道,我们以前创建的web工程下面会有一个webapp的目录,我们只要把静态资源放在该目录下就可以直接访问.但是,基于Spring boot的工程并没有这个目录,那我们应该怎么处理? 一.最笨的方式 我们首先来分享一种最笨的办法,就是将静态资源通过流直接返回给前端,我们在maven工程的resources的根目录下建立一个html的目录,然后我们把html文件放在该目

spring boot 静态资源的映射规则 (2) 替他资源映射

1.如果不是    /webjars/** 资源 if (!registry.hasMappingForPattern("/webjars/**")) { this.customizeResourceHandlerRegistration(registry.addResourceHandler(new String[]{"/webjars/**"}).addResourceLocations(new String[]{"classpath:/META-IN

spring boot 静态资源的映射规则 (3) 欢迎页面映射

欢迎 页面映射   会从 4个静态资源目录 + 根路径 / 中 查找 index.html 页面 会在 静态资源目录下 与 根路径查找 (按该顺序) index.html页面: 收到 "/**" 请求映射 访问 localhost:8080/ 会在上面5个目录中查找 index.html 页面(因为/也属于 /** ) 原文地址:https://www.cnblogs.com/guangzhou11/p/12388954.html

spring boot开发 静态资源加载不出来

spring boot 1.5 版本之前 不拦截静态资源 springboot 2.x版本 拦截静态资源 private static final String[] CLASSPATH_RESOURCE_LOCATIONS = { "classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/&quo

Spring Boot 访问静态资源

方法1一: 在resources目录下建立static的目录,将静态资源放到此处,可以直接访问 访问:127.0.0.1:9010/img/123.png 原文地址:https://www.cnblogs.com/chenglc/p/10641619.html

spring boot 静态资源的映射规则 (1) webjars 资源映射

我们可以在   WebMvcAutoConfiguration 这个类下查找一个方法    addResourceHandlers public void addResourceHandlers(ResourceHandlerRegistry registry) { if (!this.resourceProperties.isAddMappings()) { logger.debug("Default resource handling disabled"); } else { Du

【Spring Boot】Spring Boot修改静态资源后立即生效

application.properties属性文件增加一行配置: spring.thymeleaf.cache=false

【Spring学习笔记-MVC-14】Spring MVC对静态资源的访问

作者:ssslinppp       参考链接: http://www.cnblogs.com/luxh/archive/2013/03/14/2959207.html http://www.cnblogs.com/fangqi/archive/2012/10/28/2743108.html 优雅REST风格的资源URL不希望带 .html 或 .do 等后缀.由于早期的Spring MVC不能很好地处理静态资源,所以在web.xml中配置DispatcherServlet的请求映射,往往使用