本文整理汇总了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));
}
示例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);
}
}
示例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));
}
示例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;
}
});
}
示例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));
}
示例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));
}
示例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));
}
示例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());
}
示例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;
}
});
}
示例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());
}
示例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());
}
示例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;
}