SpringBoot specify the location of the resource file

SpringBoot default storage location is the static resource files in:

inside.

Note: SpringBoot in src / main / resources / resources folder corresponding to the classpath :.

The default storage location of the static resource files, files in SpringBoot project folder location is:

 

Note: At this point the four default folders are ineffective, if you want four default folders are still valid, you can add many times that four specified in the configuration folder by .addResourceHandler class.

Second way: through a configuration file

# Set when the URI is / static / **, just been to static resources

# Note: If set / **, then access will represent any path through the static resources

spring.mvc.static-path-pattern=/static/**

# Custom Path

# Note: The custom path, four default folders "resoures file in the META-INF folder under the still valid, three other folders fail

# (In this case: Access ip: port number / static / time, corresponding to access to the "custom file folders" and "resoures META-INF files in folder");

# Note: when searching for files, priority custom folders to be higher than the default four folders

spring.resources.static-locations=classpath:/static/

# Tip: If we explicitly to custom folders and four default folders down, and it will be effective (this time, the priority order from left to right)

#spring.resources.static-locations = classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,classpath:/myFile/

Recommended use Second, use 1 when it seems otherwise normal request will be intercepted, resulting in can not access

 

Transfer: https: //www.jianshu.com/p/e8849e2c3195




Guess you like

Origin www.cnblogs.com/zouhong/p/11834845.html