springboot springMVC默认访问的静态资源

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目录下放了图片。

源码目录:

springboot springMVC默认访问的静态资源_第1张图片

编译之后target目录:

springboot springMVC默认访问的静态资源_第2张图片

项目启动访问情况:

项目启动访问情况:

可以访问的:

                http://localhost:8088/pics/fj.jpg,

                http://localhost:8088/libs/fj1.jpg,

                http://localhost:8088/fj3.jpg

springboot springMVC默认访问的静态资源_第3张图片

   访问出错的:

                http://localhost:8088/fj4.jpg ,http://localhost:8088/libs/fj2.jpg

  springboot springMVC默认访问的静态资源_第4张图片

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

  springMVC默认静态资源路径为 /resources/static/

转载于:https://my.oschina.net/u/2471663/blog/811940

你可能感兴趣的:(springboot springMVC默认访问的静态资源)