IT虾米网

spring boot开发 静态资源加载不出来

mate10pro 2018年05月26日 编程语言 1809 0

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); 
		} 
	} 

  

评论关闭
IT虾米网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!