diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandler.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandler.java index e49cc2b66a7..274602b8f79 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandler.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandler.java @@ -315,6 +315,9 @@ public class ResourceHttpRequestHandler extends WebContentGenerator implements H resourcePath = resource.getURL().getPath(); locationPath = location.getURL().getPath(); } + if(locationPath.equals(resourcePath)) { + return true; + } locationPath = (locationPath.endsWith("/") || !StringUtils.hasLength(locationPath) ? locationPath : locationPath + "/"); if (!resourcePath.startsWith(locationPath)) { diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandlerTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandlerTests.java index 956238f7445..df27a76ebc8 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandlerTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandlerTests.java @@ -280,6 +280,22 @@ public class ResourceHttpRequestHandlerTests { } + // SPR-12747 + @Test + public void getResourceWithResourceLocation() throws Exception { + List resourcePaths = new ArrayList(); + resourcePaths.add(new ClassPathResource("test/foo.css", getClass())); + this.handler.setLocations(resourcePaths); + MockHttpServletRequest request = new MockHttpServletRequest(); + request.setAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, "/foo.css"); + request.setMethod("GET"); + MockHttpServletResponse response = new MockHttpServletResponse(); + handler.handleRequest(request, response); + assertEquals("text/css", response.getContentType()); + assertEquals(17, response.getContentLength()); + } + + private static class TestServletContext extends MockServletContext { @Override