zoukankan      html  css  js  c++  java
  • springboot静态资源映射

    springboot静态资源映射

    WebMvcAutoConfiguration

    	@Override		
    	public void addResourceHandlers(ResourceHandlerRegistry registry) {
    			if (!this.resourceProperties.isAddMappings()) {
    				logger.debug("Default resource handling disabled");
    				return;
    			}
    			Duration cachePeriod = this.resourceProperties.getCache().getPeriod();
    			CacheControl cacheControl = this.resourceProperties.getCache()
    					.getCachecontrol().toHttpCacheControl();
                // 读取webjars下的静态文件
                // classpath:/META-INF/resources/webjars/
    			if (!registry.hasMappingForPattern("/webjars/**")) {
    				customizeResourceHandlerRegistration(registry
    						.addResourceHandler("/webjars/**")
    						.addResourceLocations("classpath:/META-INF/resources/webjars/")
    						.setCachePeriod(getSeconds(cachePeriod))
    						.setCacheControl(cacheControl));
    			}
                // 静态资源文件夹映射
                // {"classpath:/META-INF/resources/", "classpath:/resources/","classpath:/static/", "classpath:/public/" }
    			String staticPathPattern = this.mvcProperties.getStaticPathPattern();
    			if (!registry.hasMappingForPattern(staticPathPattern)) {
    				customizeResourceHandlerRegistration(
    						registry.addResourceHandler(staticPathPattern)
    								.addResourceLocations(getResourceLocations(
    										this.resourceProperties.getStaticLocations()))
    								.setCachePeriod(getSeconds(cachePeriod))
    								.setCacheControl(cacheControl));
    			}
    		}
    
    		// 欢迎页  /**
    		@Bean
    		public WelcomePageHandlerMapping welcomePageHandlerMapping(
    				ApplicationContext applicationContext) {
    			return new WelcomePageHandlerMapping(
    					new TemplateAvailabilityProviders(applicationContext),
    					applicationContext, getWelcomePage(),
    					this.mvcProperties.getStaticPathPattern());
    		}
    

    静态资源路径可以自定义:

    spring.resources.static-locations=classpath:/xxx/,classpath:/yyy/,classpath:/zzz/
    
  • 相关阅读:
    微擎二次开发
    linux
    自动自发与强制要求的差别
    金老师的经典著作《一个普通IT人的十年回顾》
    离开了公司,你还有什么
    [转]想靠写程序赚更多钱,写到两眼通红,写得比别人都又快又好好几倍,结果又能如何?
    挨踢人生路--记我的10年18家工作经历 续 .转
    论优越感
    当程序员的那些狗日日子-----转载
    C#语法杂谈
  • 原文地址:https://www.cnblogs.com/yanfei1819/p/9668840.html
Copyright © 2011-2022 走看看