Skip to content

Commit ccc7d0f

Browse files
committed
fixed interaction with ControllerClassNameHandlerMapping (as reported by Rossen)
1 parent 87eb3f9 commit ccc7d0f

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationControllerTests.java

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,30 @@ public void standardHandleMethod() throws Exception {
137137
assertEquals("test", response.getContentAsString());
138138
}
139139

140+
@Test
141+
public void emptyRequestMapping() throws Exception {
142+
servlet = new DispatcherServlet() {
143+
@Override
144+
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) {
145+
GenericWebApplicationContext wac = new GenericWebApplicationContext();
146+
wac.registerBeanDefinition("controller", new RootBeanDefinition(ControllerWithEmptyMapping.class));
147+
RootBeanDefinition mbd = new RootBeanDefinition(ControllerClassNameHandlerMapping.class);
148+
mbd.getPropertyValues().add("excludedPackages", null);
149+
mbd.getPropertyValues().add("order", 0);
150+
wac.registerBeanDefinition("mapping", mbd);
151+
wac.registerBeanDefinition("mapping2", new RootBeanDefinition(DefaultAnnotationHandlerMapping.class));
152+
wac.refresh();
153+
return wac;
154+
}
155+
};
156+
servlet.init(new MockServletConfig());
157+
158+
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/servletannotationcontrollertests.controllerwithemptymapping");
159+
MockHttpServletResponse response = new MockHttpServletResponse();
160+
servlet.service(request, response);
161+
assertEquals("test", response.getContentAsString());
162+
}
163+
140164
@Test
141165
public void customAnnotationController() throws Exception {
142166
initServlet(CustomAnnotationController.class);
@@ -1350,10 +1374,10 @@ protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpSer
13501374
}
13511375
}
13521376

1353-
/** @noinspection UnusedDeclaration */
1354-
private static class BaseController {
1377+
@Controller
1378+
private static class ControllerWithEmptyMapping {
13551379

1356-
@RequestMapping(method = RequestMethod.GET)
1380+
@RequestMapping
13571381
public void myPath2(HttpServletResponse response) throws IOException {
13581382
response.getWriter().write("test");
13591383
}

0 commit comments

Comments
 (0)