Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of static Resource access in SpringBoot

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Today, the editor will share with you the relevant knowledge points about the method of static resource access in SpringBoot. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.

I. Overview

Springboot default static resource access path is: / static or / public or / resources or / META-INF/resources must be defined in the src/main/resources directory file, so that the project can be automatically loaded into the project static address directory under classpath when the project starts. The static access address is actually loaded into WebMvcConfigurerAdapter using the ResourceHttpRequestHandler core processor to overwrite the addResourceHandlers method. Redefine the static access directory. We can also implement the methods, and manually specify the static access path to achieve the desired effect by inheriting the WebMvcConfigurerAdapter override internal method addResourceHandlers.

The first way: put it in the src/main/webapp directory

Static resources placed in the webapp directory can be accessed directly

User.html

2.png

Reference 2.png in user.html

The second way: put it under classpath

Instructions in ResourceProperties

Org.springframework.boot.autoconfigure.web.ResourceProperties private static final String [] CLASSPATH_RESOURCE_LOCATIONS = {"classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/"}

Static resources are placed under the classpath path by default: Defaults to classpath: [/ META-INF/resources/,/resources/, / static/, / public/] plus context:/ (the root of the servlet context).

Person/index.html

Insert title here sayHello (); person page HTML

Set the location of the static resource by modifying the configuration item

Application.properties# modifies the default static resource storage directory spring.resources.static-locations=classpath:/web/

These are all the contents of this article entitled "methods for accessing static Resources in SpringBoot". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to 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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report