1.WebMvcAutoConfiguration.class中找到getWelcomePage方法
private Optional<Resource> getWelcomePage() { String[] locations = WebMvcAutoConfiguration.getResourceLocations(this.resourceProperties.getStaticLocations()); return Arrays.stream(locations).map(this::getIndexHtml).filter(this::isReadable).findFirst(); } private Resource getIndexHtml(String location) { //index.html return this.resourceLoader.getResource(location + "index.html"); }2.this.resourceProperties.getStaticLocations(),查看此方法。
public String[] getStaticLocations() { return this.staticLocations; }3.返回this.staticLocations;继续查看
private static final String[] CLASSPATH_RESOURCE_LOCATIONS = new String[]{"classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/"}; private String[] staticLocations; ... this.staticLocations = CLASSPATH_RESOURCE_LOCATIONS; ...4.发现首页的位置与静态资源导入的位置一致。所以我们就知道如何去使用首页了。