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/
    
  • 相关阅读:
    javascript常用对象
    oracle储存过程,job,视图,触发器(记性不好,写个例子自己记)
    xml直接读取节点
    脑瓜子的文章导航 脑瓜子的学院系列文章汇总
    ASP.NET MVC 中实现View与Controller分离
    开发
    SQLite学习手册(转)
    缓存数据库redis、memcached。 MongoDB 资源集锦
    在GOOGLE浏览器中模拟移动浏览器 调试Web app
    Intelligencia.UrlRewriter在IIS 7.0下的完全配置攻略
  • 原文地址:https://www.cnblogs.com/yanfei1819/p/9668840.html
Copyright © 2011-2022 走看看