Fix PrefixResourceResolver implementation

The configured prefix should not begin with a "/", since
PublicResourceUrlProvider is already taking path mapping into account
when resolving resources and URLs.
master
Brian Clozel 11 years ago
parent bded025d9f
commit c4843577ba
  1. 2
      spring-webmvc/src/main/java/org/springframework/web/servlet/resource/PrefixResourceResolver.java
  2. 4
      spring-webmvc/src/test/java/org/springframework/web/servlet/resource/PrefixResourceResolverTests.java

@ -50,7 +50,7 @@ public class PrefixResourceResolver extends AbstractResourceResolver {
public PrefixResourceResolver(String prefix) {
Assert.hasText(prefix, "prefix must not be null or empty");
this.prefix = prefix.startsWith("/") ? prefix : "/" + prefix;
this.prefix = prefix.startsWith("/") ? prefix.substring(1) : prefix;
}
@Override

@ -54,14 +54,14 @@ public class PrefixResourceResolverTests {
public void resolveResource() {
String resourceId = "foo.css";
Resource expected = new ClassPathResource("test/foo.css", getClass());
Resource actual = this.chain.resolveResource(null, "/" + this.shaPrefix + "/" + resourceId, this.locations);
Resource actual = this.chain.resolveResource(null, this.shaPrefix + "/" + resourceId, this.locations);
assertEquals(expected, actual);
}
@Test
public void resolvePublicUrlPath() {
String resourceId = "/foo.css";
String url = "/" + this.shaPrefix + resourceId;
String url = this.shaPrefix + resourceId;
assertEquals(url, chain.resolvePublicUrlPath(resourceId, locations));
}

Loading…
Cancel
Save