提交 ead5df45 编写于 作者: A Arjen Poutsma

SPR-6649 - Request mapping incorrectly receiving all dispatches for a controller

上级 2f840b10
......@@ -596,7 +596,7 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
return null;
}
String bestMatchingPattern = (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
if (StringUtils.hasText(bestMatchingPattern)) {
if (StringUtils.hasText(bestMatchingPattern) && bestMatchingPattern.endsWith("*")) {
String combinedPattern = pathMatcher.combine(bestMatchingPattern, methodLevelPattern);
if (!combinedPattern.equals(bestMatchingPattern) &&
(isPathMatchInternal(combinedPattern, lookupPath))) {
......
......@@ -204,8 +204,20 @@ public class ServletAnnotationControllerTests {
@Test
public void defaultExpressionParameters() throws Exception {
initServlet(DefaultExpressionValueParamController.class);
servlet = new DispatcherServlet() {
@Override
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) {
GenericWebApplicationContext wac = new GenericWebApplicationContext();
wac.registerBeanDefinition("controller", new RootBeanDefinition(DefaultExpressionValueParamController.class));
RootBeanDefinition ppc = new RootBeanDefinition(PropertyPlaceholderConfigurer.class);
ppc.getPropertyValues().add("properties", "myKey=foo");
wac.registerBeanDefinition("ppc", ppc);
wac.refresh();
return wac;
}
};
servlet.init(new MockServletConfig());
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myApp/myPath.do");
request.setContextPath("/myApp");
MockHttpServletResponse response = new MockHttpServletResponse();
......@@ -344,9 +356,6 @@ public class ServletAnnotationControllerTests {
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) {
GenericWebApplicationContext wac = new GenericWebApplicationContext();
wac.registerBeanDefinition("controller", new RootBeanDefinition(controllerClass));
RootBeanDefinition ppc = new RootBeanDefinition(PropertyPlaceholderConfigurer.class);
ppc.getPropertyValues().add("properties", "myKey=foo");
wac.registerBeanDefinition("ppc", ppc);
wac.refresh();
return wac;
}
......@@ -1279,6 +1288,16 @@ public class ServletAnnotationControllerTests {
assertEquals("handle", response.getContentAsString());
}
@Test
public void trailingSlash() throws Exception {
initServlet(TrailingSlashController.class);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo/");
MockHttpServletResponse response = new MockHttpServletResponse();
servlet.service(request, response);
assertEquals("templatePath", response.getContentAsString());
}
/*
* Controllers
......@@ -2206,5 +2225,19 @@ public class ServletAnnotationControllerTests {
}
}
@Controller
public static class TrailingSlashController {
@RequestMapping(value = "/", method = RequestMethod.GET)
public void root(Writer writer) throws IOException {
writer.write("root");
}
@RequestMapping(value = "/{templatePath}/", method = RequestMethod.GET)
public void templatePath(Writer writer) throws IOException {
writer.write("templatePath");
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册