org.springframework.web.servlet.config.annotation.ResourceHandlerRegistration Java Examples

The following examples show how to use org.springframework.web.servlet.config.annotation.ResourceHandlerRegistration. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StaticResourceConfiguration.java    From difido-reports with Apache License 2.0 6 votes vote down vote up
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
	String docRoot = il.co.topq.report.Configuration.INSTANCE.readString(ConfigProps.DOC_ROOT_FOLDER);
	if (null == docRoot || docRoot.isEmpty()) {
		docRoot = "docRoot/";
	}
	if (!docRoot.endsWith("/")) {
		docRoot += "/";
	}
	log.debug("docRoot folder is set to " + docRoot);

	ResourceHandlerRegistration resourceHandlerRegistration = registry.addResourceHandler("/**")
			.addResourceLocations("file:" + docRoot);

	boolean enableArchivedResources = il.co.topq.report.Configuration.INSTANCE
			.readBoolean(ConfigProps.ENABLE_ARCHIVED_RESOURCES);
	log.debug("enableArchivedResources={}", enableArchivedResources);
	if (enableArchivedResources) {
		// many of our resources are dynamic
		// so we probably don't want to cache them.
		resourceHandlerRegistration.resourceChain(false).addResolver(new GzipArchivedResourceResolver())
				.addResolver(new PathResourceResolver());
	}

}
 
Example #2
Source File: MvcConfiguration.java    From alf.io with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    ResourceHandlerRegistration reg = registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
    boolean isLive = environment.acceptsProfiles(Profiles.of(Initializer.PROFILE_LIVE));
    int cacheMinutes = isLive ? 15 : 0;
    reg.setCachePeriod(cacheMinutes * 60);

    //
    registry
        .addResourceHandler("/webjars/**")
        .addResourceLocations("/webjars/")
        .setCacheControl(CacheControl.maxAge(Duration.ofDays(isLive ? 10 : 0)).mustRevalidate());

    registry.addResourceHandler("/assets/**")
        .addResourceLocations("/webjars/alfio-public-frontend/" + frontendVersion + "/alfio-public-frontend/assets/");

}
 
Example #3
Source File: WebMvcConfig.java    From Roothub with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 静态资源映射
 */
@Override
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
	Map<String, Object> maps = systemConfigService.getUploadConfig();
	/**
	 * 上传类型
	 * 29: 默认上传
	 * 30: 自定义上传
	 * 45: 阿里云OSS上传
	 */
	String uploadType = (String)maps.get("upload_type");
	if(!uploadType.equals("45")) {
		// 数据库里配置的静态资源访问URL
		String staticUrl = (String)maps.get("static_url");
		// 数据库里配置的静态资源映射目录
		String uploadFiledir = (String)maps.get("default_upload_filedir") != null ? (String)maps.get("default_upload_filedir") : (String)maps.get("local_upload_filedir");
		// 自定义的静态资源映射目录,这里是写死的
		String[] locations = {
				uploadFiledir + "topic/",
				uploadFiledir + "node/",
				uploadFiledir + "user/",
				uploadFiledir + "tag/",
				uploadFiledir + "admin-user/"
				};
		// 添加静态资源访问URL
		ResourceHandlerRegistration addResourceLocations = registry.addResourceHandler(staticUrl);
		for(String location : locations) {
			// 添加静态资源映射目录
			addResourceLocations.addResourceLocations(location);
		}
	}
}
 
Example #4
Source File: FreemarkerTemplateinheritanceConfig.java    From freemarker-template-inheritance with Apache License 2.0 4 votes vote down vote up
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    ResourceHandlerRegistration resourceHandlerRegistration = registry.addResourceHandler("/resources");
    resourceHandlerRegistration.addResourceLocations("/WEB-INF/resources");
    resourceHandlerRegistration.setCachePeriod(0);
}