当前位置: 首页>>代码示例>>Java>>正文


Java PathResourceResolver类代码示例

本文整理汇总了Java中org.springframework.web.servlet.resource.PathResourceResolver的典型用法代码示例。如果您正苦于以下问题:Java PathResourceResolver类的具体用法?Java PathResourceResolver怎么用?Java PathResourceResolver使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PathResourceResolver类属于org.springframework.web.servlet.resource包,在下文中一共展示了PathResourceResolver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: resourceChain

import org.springframework.web.servlet.resource.PathResourceResolver; //导入依赖的package包/类
@Test
public void resourceChain() throws Exception {
	ResourceResolver mockResolver = Mockito.mock(ResourceResolver.class);
	ResourceTransformer mockTransformer = Mockito.mock(ResourceTransformer.class);
	this.registration.resourceChain(true).addResolver(mockResolver).addTransformer(mockTransformer);

	ResourceHttpRequestHandler handler = getHandler("/resources/**");
	List<ResourceResolver> resolvers = handler.getResourceResolvers();
	assertThat(resolvers.toString(), resolvers, Matchers.hasSize(4));
	assertThat(resolvers.get(0), Matchers.instanceOf(CachingResourceResolver.class));
	CachingResourceResolver cachingResolver = (CachingResourceResolver) resolvers.get(0);
	assertThat(cachingResolver.getCache(), Matchers.instanceOf(ConcurrentMapCache.class));
	assertThat(resolvers.get(1), Matchers.equalTo(mockResolver));
	assertThat(resolvers.get(2), Matchers.instanceOf(WebJarsResourceResolver.class));
	assertThat(resolvers.get(3), Matchers.instanceOf(PathResourceResolver.class));

	List<ResourceTransformer> transformers = handler.getResourceTransformers();
	assertThat(transformers, Matchers.hasSize(2));
	assertThat(transformers.get(0), Matchers.instanceOf(CachingResourceTransformer.class));
	assertThat(transformers.get(1), Matchers.equalTo(mockTransformer));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:ResourceHandlerRegistryTests.java

示例2: addResourceHandlers

import org.springframework.web.servlet.resource.PathResourceResolver; //导入依赖的package包/类
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/index.html")
            .addResourceLocations("classpath:/public/", "classpath:/static/")
            .setCacheControl(createCacheConfig(maxIndexCacheAge))
            .resourceChain(true)
            .addResolver(new PathResourceResolver());

    final ResourceChainRegistration registration = registry.addResourceHandler("/**")
            .addResourceLocations("classpath:/public/", "classpath:/static/",
                    "classpath:/META-INF/resources/")
            .setCacheControl(createCacheConfig(maxCacheAge))
            .resourceChain(true)
            .addResolver(new PathResourceResolver());

    if (propertyInjectionTransformer != null) {
        registration.addTransformer(propertyInjectionTransformer);
    }
}
 
开发者ID:redlink-gmbh,项目名称:smarti,代码行数:20,代码来源:StaticWebResourceConfiguration.java

示例3: resourceChainWithVersionResolver

import org.springframework.web.servlet.resource.PathResourceResolver; //导入依赖的package包/类
@Test
public void resourceChainWithVersionResolver() throws Exception {
	VersionResourceResolver versionResolver = new VersionResourceResolver()
			.addFixedVersionStrategy("fixed", "/**/*.js")
			.addContentVersionStrategy("/**");

	this.registration.resourceChain(true).addResolver(versionResolver)
			.addTransformer(new AppCacheManifestTransformer());

	ResourceHttpRequestHandler handler = getHandler("/resources/**");
	List<ResourceResolver> resolvers = handler.getResourceResolvers();
	assertThat(resolvers.toString(), resolvers, Matchers.hasSize(4));
	assertThat(resolvers.get(0), Matchers.instanceOf(CachingResourceResolver.class));
	assertThat(resolvers.get(1), Matchers.sameInstance(versionResolver));
	assertThat(resolvers.get(2), Matchers.instanceOf(WebJarsResourceResolver.class));
	assertThat(resolvers.get(3), Matchers.instanceOf(PathResourceResolver.class));

	List<ResourceTransformer> transformers = handler.getResourceTransformers();
	assertThat(transformers, Matchers.hasSize(3));
	assertThat(transformers.get(0), Matchers.instanceOf(CachingResourceTransformer.class));
	assertThat(transformers.get(1), Matchers.instanceOf(CssLinkResourceTransformer.class));
	assertThat(transformers.get(2), Matchers.instanceOf(AppCacheManifestTransformer.class));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:ResourceHandlerRegistryTests.java

示例4: addResourceHandlers

import org.springframework.web.servlet.resource.PathResourceResolver; //导入依赖的package包/类
@Override
public void addResourceHandlers(final ResourceHandlerRegistry registry) {
    Integer cachePeriod = resourceProperties.getCachePeriod();

    final String[] staticLocations = resourceProperties.getStaticLocations();
    final String[] indexLocations = new String[staticLocations.length];
    for (int i = 0; i < staticLocations.length; i++) {
        indexLocations[i] = staticLocations[i] + "index.html";
    }
    registry.addResourceHandler(
            "/**/*.css",
            "/**/*.html",
            "/**/*.js",
            "/**/*.json",
            "/**/*.bmp",
            "/**/*.jpeg",
            "/**/*.jpg",
            "/**/*.png",
            "/**/*.ttf",
            "/**/*.eot",
            "/**/*.svg",
            "/**/*.woff",
            "/**/*.woff2"
    )
            .addResourceLocations(staticLocations)
            .setCachePeriod(cachePeriod);

    registry.addResourceHandler("/**")
            .addResourceLocations(indexLocations)
            .setCachePeriod(cachePeriod)
            .resourceChain(true)
            .addResolver(new PathResourceResolver() {
                @Override
                protected Resource getResource(final String resourcePath,
                                               final Resource location) throws IOException {
                    return location.exists() && location.isReadable() ? location : null;
                }
            });
}
 
开发者ID:vlsidlyarevich,项目名称:unity,代码行数:40,代码来源:WebConfig.java

示例5: resourceHandlerFixedStrategyEnabled

import org.springframework.web.servlet.resource.PathResourceResolver; //导入依赖的package包/类
@Test
public void resourceHandlerFixedStrategyEnabled() throws Exception {
	load("spring.resources.chain.strategy.fixed.enabled:true",
			"spring.resources.chain.strategy.fixed.version:test",
			"spring.resources.chain.strategy.fixed.paths:/**/*.js");
	assertThat(getResourceResolvers("/webjars/**")).hasSize(3);
	assertThat(getResourceTransformers("/webjars/**")).hasSize(2);
	assertThat(getResourceResolvers("/**")).extractingResultOf("getClass")
			.containsOnly(CachingResourceResolver.class,
					VersionResourceResolver.class, PathResourceResolver.class);
	assertThat(getResourceTransformers("/**")).extractingResultOf("getClass")
			.containsOnly(CachingResourceTransformer.class,
					CssLinkResourceTransformer.class);
	VersionResourceResolver resolver = (VersionResourceResolver) getResourceResolvers(
			"/**").get(1);
	assertThat(resolver.getStrategyMap().get("/**/*.js"))
			.isInstanceOf(FixedVersionStrategy.class);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:19,代码来源:WebMvcAutoConfigurationTests.java

示例6: resourceHandlerContentStrategyEnabled

import org.springframework.web.servlet.resource.PathResourceResolver; //导入依赖的package包/类
@Test
public void resourceHandlerContentStrategyEnabled() throws Exception {
	load("spring.resources.chain.strategy.content.enabled:true",
			"spring.resources.chain.strategy.content.paths:/**,/*.png");
	assertThat(getResourceResolvers("/webjars/**")).hasSize(3);
	assertThat(getResourceTransformers("/webjars/**")).hasSize(2);
	assertThat(getResourceResolvers("/**")).extractingResultOf("getClass")
			.containsOnly(CachingResourceResolver.class,
					VersionResourceResolver.class, PathResourceResolver.class);
	assertThat(getResourceTransformers("/**")).extractingResultOf("getClass")
			.containsOnly(CachingResourceTransformer.class,
					CssLinkResourceTransformer.class);
	VersionResourceResolver resolver = (VersionResourceResolver) getResourceResolvers(
			"/**").get(1);
	assertThat(resolver.getStrategyMap().get("/*.png"))
			.isInstanceOf(ContentVersionStrategy.class);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:18,代码来源:WebMvcAutoConfigurationTests.java

示例7: resourceHandlerChainCustomized

import org.springframework.web.servlet.resource.PathResourceResolver; //导入依赖的package包/类
@Test
public void resourceHandlerChainCustomized() throws Exception {
	load("spring.resources.chain.enabled:true", "spring.resources.chain.cache:false",
			"spring.resources.chain.strategy.content.enabled:true",
			"spring.resources.chain.strategy.content.paths:/**,/*.png",
			"spring.resources.chain.strategy.fixed.enabled:true",
			"spring.resources.chain.strategy.fixed.version:test",
			"spring.resources.chain.strategy.fixed.paths:/**/*.js",
			"spring.resources.chain.html-application-cache:true",
			"spring.resources.chain.gzipped:true");
	assertThat(getResourceResolvers("/webjars/**")).hasSize(3);
	assertThat(getResourceTransformers("/webjars/**")).hasSize(2);
	assertThat(getResourceResolvers("/**")).extractingResultOf("getClass")
			.containsOnly(VersionResourceResolver.class, GzipResourceResolver.class,
					PathResourceResolver.class);
	assertThat(getResourceTransformers("/**")).extractingResultOf("getClass")
			.containsOnly(CssLinkResourceTransformer.class,
					AppCacheManifestTransformer.class);
	VersionResourceResolver resolver = (VersionResourceResolver) getResourceResolvers(
			"/**").get(0);
	assertThat(resolver.getStrategyMap().get("/*.png"))
			.isInstanceOf(ContentVersionStrategy.class);
	assertThat(resolver.getStrategyMap().get("/**/*.js"))
			.isInstanceOf(FixedVersionStrategy.class);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:26,代码来源:WebMvcAutoConfigurationTests.java

示例8: resourceHandlerFixedStrategyEnabled

import org.springframework.web.servlet.resource.PathResourceResolver; //导入依赖的package包/类
@Test
public void resourceHandlerFixedStrategyEnabled() throws Exception {
	load("spring.resources.chain.strategy.fixed.enabled:true",
			"spring.resources.chain.strategy.fixed.version:test",
			"spring.resources.chain.strategy.fixed.paths:/**/*.js");
	assertThat(getResourceResolvers("/webjars/**").size(), equalTo(3));
	assertThat(getResourceTransformers("/webjars/**").size(), equalTo(2));
	assertThat(getResourceResolvers("/**").size(), equalTo(3));
	assertThat(getResourceTransformers("/**").size(), equalTo(2));
	assertThat(getResourceResolvers("/**"),
			containsInstances(CachingResourceResolver.class,
					VersionResourceResolver.class, PathResourceResolver.class));
	assertThat(getResourceTransformers("/**"), containsInstances(
			CachingResourceTransformer.class, CssLinkResourceTransformer.class));
	VersionResourceResolver resolver = (VersionResourceResolver) getResourceResolvers(
			"/**").get(1);
	assertThat(resolver.getStrategyMap().get("/**/*.js"),
			instanceOf(FixedVersionStrategy.class));
}
 
开发者ID:Nephilim84,项目名称:contestparser,代码行数:20,代码来源:WebMvcAutoConfigurationTests.java

示例9: resourceHandlerContentStrategyEnabled

import org.springframework.web.servlet.resource.PathResourceResolver; //导入依赖的package包/类
@Test
public void resourceHandlerContentStrategyEnabled() throws Exception {
	load("spring.resources.chain.strategy.content.enabled:true",
			"spring.resources.chain.strategy.content.paths:/**,/*.png");
	assertThat(getResourceResolvers("/webjars/**").size(), equalTo(3));
	assertThat(getResourceTransformers("/webjars/**").size(), equalTo(2));
	assertThat(getResourceResolvers("/**").size(), equalTo(3));
	assertThat(getResourceTransformers("/**").size(), equalTo(2));
	assertThat(getResourceResolvers("/**"),
			containsInstances(CachingResourceResolver.class,
					VersionResourceResolver.class, PathResourceResolver.class));
	assertThat(getResourceTransformers("/**"), containsInstances(
			CachingResourceTransformer.class, CssLinkResourceTransformer.class));
	VersionResourceResolver resolver = (VersionResourceResolver) getResourceResolvers(
			"/**").get(1);
	assertThat(resolver.getStrategyMap().get("/*.png"),
			instanceOf(ContentVersionStrategy.class));
}
 
开发者ID:Nephilim84,项目名称:contestparser,代码行数:19,代码来源:WebMvcAutoConfigurationTests.java

示例10: resourceHandlerChainCustomized

import org.springframework.web.servlet.resource.PathResourceResolver; //导入依赖的package包/类
@Test
public void resourceHandlerChainCustomized() throws Exception {
	load("spring.resources.chain.enabled:true", "spring.resources.chain.cache:false",
			"spring.resources.chain.strategy.content.enabled:true",
			"spring.resources.chain.strategy.content.paths:/**,/*.png",
			"spring.resources.chain.strategy.fixed.enabled:true",
			"spring.resources.chain.strategy.fixed.version:test",
			"spring.resources.chain.strategy.fixed.paths:/**/*.js",
			"spring.resources.chain.html-application-cache:true");
	assertThat(getResourceResolvers("/webjars/**").size(), equalTo(2));
	assertThat(getResourceTransformers("/webjars/**").size(), equalTo(2));
	assertThat(getResourceResolvers("/**").size(), equalTo(2));
	assertThat(getResourceTransformers("/**").size(), equalTo(2));
	assertThat(getResourceResolvers("/**"), containsInstances(
			VersionResourceResolver.class, PathResourceResolver.class));
	assertThat(getResourceTransformers("/**"), containsInstances(
			CssLinkResourceTransformer.class, AppCacheManifestTransformer.class));
	VersionResourceResolver resolver = (VersionResourceResolver) getResourceResolvers(
			"/**").get(0);
	assertThat(resolver.getStrategyMap().get("/*.png"),
			instanceOf(ContentVersionStrategy.class));
	assertThat(resolver.getStrategyMap().get("/**/*.js"),
			instanceOf(FixedVersionStrategy.class));
}
 
开发者ID:Nephilim84,项目名称:contestparser,代码行数:25,代码来源:WebMvcAutoConfigurationTests.java

示例11: addResourceHandlers

import org.springframework.web.servlet.resource.PathResourceResolver; //导入依赖的package包/类
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry
            .addResourceHandler("/resources/**")
            .addResourceLocations("/resources/")
            .setCachePeriod(3600)
            .resourceChain(true)
            .addResolver(new PathResourceResolver());
}
 
开发者ID:EventSoftGroup,项目名称:EventSoft,代码行数:10,代码来源:MvcConfig.java

示例12: addResourceHandlers

import org.springframework.web.servlet.resource.PathResourceResolver; //导入依赖的package包/类
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler(STATIC_RESOURCES)
        .addResourceLocations(resourceProperties.getStaticLocations());

    registry.addResourceHandler("/**")
        .addResourceLocations(getIndexLocations())
        .resourceChain(true)
        .addResolver(new PathResourceResolver() {
            @Override
            protected Resource getResource(String resourcePath, Resource location) throws IOException {
                return location.exists() && location.isReadable() ? location : null;
            }
        });
}
 
开发者ID:dreyman,项目名称:inpacker,代码行数:16,代码来源:WebConfig.java

示例13: addResourceHandlers

import org.springframework.web.servlet.resource.PathResourceResolver; //导入依赖的package包/类
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
  registry.addResourceHandler("/*.*", "/ico/**", "/reports/**", "swagger-ui.html", "/webjars/**")
    .addResourceLocations("/site/", "/site/ico/", "file:" + reportRootPath(),
      "classpath:/META-INF/resources/", "classpath:/META-INF/resources/webjars/")
    .resourceChain(true)
    .addResolver(new GzipResourceResolver())
    .addResolver(new PathResourceResolver());
}
 
开发者ID:aol,项目名称:chronos,代码行数:10,代码来源:TestConfig.java

示例14: addResourceHandlers

import org.springframework.web.servlet.resource.PathResourceResolver; //导入依赖的package包/类
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/resources/vendor/**")
            .addResourceLocations("/resources/vendor/")
            .setCachePeriod(0)
            .resourceChain(true)
            .addResolver(new GzipResourceResolver())
            .addResolver(new PathResourceResolver());
}
 
开发者ID:csokafor,项目名称:spring-security-angularjs,代码行数:10,代码来源:MvcConfig.java

示例15: addResolver

import org.springframework.web.servlet.resource.PathResourceResolver; //导入依赖的package包/类
/**
 * Add a resource resolver to the chain.
 * @param resolver the resolver to add
 * @return the current instance for chained method invocation
 */
public ResourceChainRegistration addResolver(ResourceResolver resolver) {
	Assert.notNull(resolver, "The provided ResourceResolver should not be null");
	this.resolvers.add(resolver);
	if (resolver instanceof VersionResourceResolver) {
		this.hasVersionResolver = true;
	}
	else if (resolver instanceof PathResourceResolver) {
		this.hasPathResolver = true;
	}
	return this;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:ResourceChainRegistration.java


注:本文中的org.springframework.web.servlet.resource.PathResourceResolver类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。