1. 程式人生 > >spring boot開發 靜態資源加載不出來

spring boot開發 靜態資源加載不出來

sta gist cati -i nal resource location ces ons

spring boot 1.5 版本之前 不攔截靜態資源

springboot 2.x版本 攔截靜態資源

private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {
			"classpath:/META-INF/resources/", "classpath:/resources/",
			"classpath:/static/", "classpath:/public/" };
	
	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		if (!registry.hasMappingForPattern("/webjars/**")) {
			registry.addResourceHandler("/webjars/**").addResourceLocations(
					"classpath:/META-INF/resources/webjars/");
		}
		if (!registry.hasMappingForPattern("/**")) {
			registry.addResourceHandler("/**").addResourceLocations(
					CLASSPATH_RESOURCE_LOCATIONS);
		}
	}

  

spring boot開發 靜態資源加載不出來