您的位置:首页 > 编程语言 > Java开发

springboot springMVC默认访问的静态资源

2016-12-26 00:00 926 查看
springMVC默认静态资源路径为: /resources/static/

classpath的指定:org.springframework.boot.autoconfigure.web.ResourceProperties

@ConfigurationProperties(
prefix = "spring.resources",
ignoreUnknownFields = false
)
public class ResourceProperties implements ResourceLoaderAware {
private static final String[] SERVLET_RESOURCE_LOCATIONS = new String[]{"/"};
private static final String[] CLASSPATH_RESOURCE_LOCATIONS =
new String[]{"classpath:/META-INF/resources/", "classpath:/resources/",
"classpath:/static/", "classpath:/public/"};
private static final String[] RESOURCE_LOCATIONS;
private String[] staticLocations;
private Integer cachePeriod;
private boolean addMappings;
private final ResourceProperties.Chain chain;
private ResourceLoader resourceLoader; public ResourceProperties() {
this.staticLocations = RESOURCE_LOCATIONS;
this.addMappings = true;
this.chain = new ResourceProperties.Chain();
}
//...
}

resources目录作为classpath,resources/static 同样是作为classpath目录

现在分别在resources,static目录下放了图片。

源码目录:



编译之后target目录:



项目启动访问情况:

项目启动访问情况:

可以访问的:
http://localhost:8088/pics/fj.jpg, http://localhost:8088/libs/fj1.jpg, http://localhost:8088/fj3.jpg


访问出错的:
http://localhost:8088/fj4.jpg ,http://localhost:8088/libs/fj2.jpg



>> fj2.jpg,fj4.jpg不在static下面,不能访问

springMVC默认静态资源路径为 /resources/static/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: