SpringBoot配置访问静态资源

application.yaml

server:
servlet:
#拦截路径
context-path: /
#端口
port: 8088
logging:
level:
#日志级别,目录: 级别
com.company: debug

org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration.java中有

@Configuration(proxyBeanMethods = false)
@Import(EnableWebMvcConfiguration.class)
@EnableConfigurationProperties({ WebMvcProperties.class, ResourceProperties.class })
@Order(0)
public static class WebMvcAutoConfigurationAdapter implements WebMvcConfigurer {

点进去ResourceProperties.class

@ConfigurationProperties(prefix = "spring.resources", ignoreUnknownFields = false)
public class ResourceProperties {

private static final String[] CLASSPATH_RESOURCE_LOCATIONS = { "classpath:/META-INF/resources/",
"classpath:/resources/", "classpath:/static/", "classpath:/public/" };

/**
* Locations of static resources. Defaults to classpath:[/META-INF/resources/,
* /resources/, /static/, /public/].
*/
private String[] staticLocations = CLASSPATH_RESOURCE_LOCATIONS;

一般使用"classpath:/static/",前后端分离的项目用不到该配置

猜你喜欢

转载自www.cnblogs.com/zou-rong/p/12565036.html
今日推荐