In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
The knowledge points of this article "SpringBoot static resource mapping method" are not quite understood by most people, so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "SpringBoot static resource mapping method" article.
Static resource mapping
SpringBoot's automatic configuration of SpringMVC is in the WebMVCAutoConfiguration class.
One of the static inner classes, WebMvcAutoConfigurationAdapter, implements the WebMvcConfigurer interface. (361)
The default mapping relationship for addResourceHandlers to handle static resources is defined in the WebMvcConfigurer interface.
AddResourceHandlers is implemented in the WebMvcAutoConfigurationAdapter class
Public void addResourceHandlers (ResourceHandlerRegistry registry) {if (! this.resourceProperties.isAddMappings ()) {logger.debug ("Default resource handling disabled");} else {Duration cachePeriod = this.resourceProperties.getCache () .getPeriod (); CacheControl cacheControl = this.resourceProperties.getCache () .getCachecontrol () .toHttpCacheControl () If (! registry.hasMappingForPattern ("/ webjars/**")) {this.customizeResourceHandlerRegistration (registry.addResourceHandler (new String [] {"/ webjars/**"}) .addResourceLocations (new String [] {"classpath:/META-INF/resources/webjars/"}) .setCachePeriod (this.getSeconds (cachePeriod)) .setCacheControl (cacheControl);} String staticPathPattern = this.mvcProperties.getStaticPathPattern () If (! registry.hasMappingForPattern (staticPathPattern)) {this.customizeResourceHandlerRegistration (registry.addResourceHandler (new String [] {staticPathPattern}) .addResourceLocations (WebMvcAutoConfiguration.getResourceLocations (this.resourceProperties.getStaticLocations () .setCachePeriod (this.getSeconds (cachePeriod)) .setCacheControl (cacheControl));}
Among them
This.resourceProperties.getStaticLocations ()
Returns the default mapping of static resources
The getStaticLocations () method is defined in ResourceProperties
Among them
Private static final String [] CLASSPATH_RESOURCE_LOCATIONS = new String [] {"classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/"}
Classpath:/META-INF/resources/
Classpath:/resources/
Classpath:/static/
Classpath:/public/
The fifth default resource mapping: defined in the static method getResourceLocations
/
Summary:
By default, static resources can be placed in the following five locations
Classpath:/META-INF/resources/classpath:/resources/classpath:/static/classpath:/public//
[static resources are generally placed in the classpath:/static/ directory]
Custom favicon, custom index.html
Favicon.ico is the icon in the upper left corner of the browser, which can be placed under the static resource path or under the classpath. The static resource path has high priority.
After SpringBoot starts, it looks for index.html in the static resource directory by default. If it is not found, it will go to the resource/templates directory to look for index.html (using Thymeleaf template).
The above is the content of this article on "the method of SpringBoot static resource mapping". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.