Static Resource Access Method in spring boot, spring boot static
I. Overview
Springboot default static resource access path:/static or/public or/resources or/META-INF/resources address must be defined in the src/main/resources directory file, in this way, the static address directory of the project can be automatically loaded to the classpath when the project is started. The static access address is actually loaded to the WebMvcConfigurerAdapter using the ResourceHttpRequestHandler core processor to overwrite the addResourceHandlers method. redefines the static access directory. We can also implement the method. Manually specify the static access path and override the internal method addResourceHandlers by inheriting WebMvcConfigurerAdapter.
Method 1: place the file in the src/main/webapp directory
Static resources stored in the webapp directory can be directly accessed.
User.html
2. png
Use 2.png in user.html
Method 2: Put it under classpath
Description 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 stored in 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
<!DOCTYPE html>
Modify configuration items to set the location of static Resources
Application. properties # modify the default static resource storage directory spring. resources. static-locations = classpath:/web/
Summary
The above is a small Editor to introduce you to the static resource access method in SpringBoot, I hope to help you, if you have any questions, please leave a message, the small editor will reply to you in a timely manner. Thank you very much for your support for the help House website!