SPR-8248
This commit is contained in:
@@ -103,7 +103,7 @@ public class HandlerMethodMappingTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getKeyForMethod(Method method) {
|
||||
protected String getKeyForMethod(String beanName, Method method) {
|
||||
String methodName = method.getName();
|
||||
return methodName.startsWith("handler") ? methodName : null;
|
||||
}
|
||||
|
||||
@@ -1157,6 +1157,7 @@ public class ServletAnnotationControllerTests {
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
try {
|
||||
servlet.service(request, response);
|
||||
fail("Didn't fail with due to ambiguous method mapping");
|
||||
}
|
||||
catch (NestedServletException ex) {
|
||||
assertTrue(ex.getCause() instanceof IllegalStateException);
|
||||
|
||||
@@ -63,7 +63,8 @@ public class RequestMappingHandlerMethodDetectionTests {
|
||||
{ new MappingInterfaceController(), false},
|
||||
{ new MappingAbstractClassController(), false},
|
||||
{ new ParameterizedInterfaceController(), false },
|
||||
{ new MappingParameterizedInterfaceController(), false },
|
||||
{ new MappingParameterizedInterfaceController(), false },
|
||||
{ new MappingClassController(), false },
|
||||
{ new MappingAbstractClassController(), true},
|
||||
{ new PlainController(), true}
|
||||
});
|
||||
@@ -80,7 +81,7 @@ public class RequestMappingHandlerMethodDetectionTests {
|
||||
|
||||
@Test
|
||||
public void detectAndMapHandlerMethod() throws Exception {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/handle");
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/type/handle");
|
||||
|
||||
TestRequestMappingHandlerMethodMapping mapping = createHandlerMapping(handler.getClass(), useAutoProxy);
|
||||
HandlerMethod handlerMethod = mapping.getHandlerInternal(request);
|
||||
@@ -110,55 +111,76 @@ public class RequestMappingHandlerMethodDetectionTests {
|
||||
}
|
||||
}
|
||||
|
||||
/* Annotation on interface method */
|
||||
|
||||
@Controller
|
||||
public interface MappingInterface {
|
||||
@RequestMapping(value="/handle", method = RequestMethod.GET)
|
||||
void handle();
|
||||
}
|
||||
|
||||
@RequestMapping(value="/type")
|
||||
public static class MappingInterfaceController implements MappingInterface {
|
||||
public void handle() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Annotation on abstract class method */
|
||||
|
||||
@Controller
|
||||
public static abstract class MappingAbstractClass {
|
||||
@RequestMapping(value = "/handle", method = RequestMethod.GET)
|
||||
public abstract void handle();
|
||||
}
|
||||
|
||||
@RequestMapping(value="/type")
|
||||
public static class MappingAbstractClassController extends MappingAbstractClass {
|
||||
public void handle() {
|
||||
}
|
||||
}
|
||||
|
||||
/* Annotation on parameterized controller method */
|
||||
|
||||
@Controller
|
||||
public interface ParameterizedInterface<T> {
|
||||
void handle(T object);
|
||||
}
|
||||
|
||||
@RequestMapping(value="/type")
|
||||
public static class ParameterizedInterfaceController implements ParameterizedInterface<TestBean> {
|
||||
@RequestMapping(value = "/handle", method = RequestMethod.GET)
|
||||
public void handle(TestBean object) {
|
||||
}
|
||||
}
|
||||
|
||||
/* Annotation on parameterized interface method */
|
||||
|
||||
@Controller
|
||||
public interface MappingParameterizedInterface<T> {
|
||||
@RequestMapping(value = "/handle", method = RequestMethod.GET)
|
||||
void handle(T object);
|
||||
}
|
||||
|
||||
@RequestMapping(value="/type")
|
||||
public static class MappingParameterizedInterfaceController implements MappingParameterizedInterface<TestBean> {
|
||||
public void handle(TestBean object) {
|
||||
}
|
||||
}
|
||||
|
||||
@Controller
|
||||
public static class PlainController {
|
||||
public PlainController() {
|
||||
}
|
||||
/* Type + method annotations, method in parent class only (SPR-8248) */
|
||||
|
||||
@Controller
|
||||
public static class MappingClass {
|
||||
@RequestMapping(value = "/handle", method = RequestMethod.GET)
|
||||
public void handle(TestBean object) {
|
||||
}
|
||||
}
|
||||
@RequestMapping(value="/type")
|
||||
public static class MappingClassController extends MappingClass {
|
||||
// Method in parent class only
|
||||
}
|
||||
|
||||
/* Annotations on controller class */
|
||||
|
||||
@Controller
|
||||
@RequestMapping(value="/type")
|
||||
public static class PlainController {
|
||||
@RequestMapping(value = "/handle", method = RequestMethod.GET)
|
||||
public void handle() {
|
||||
}
|
||||
|
||||
@@ -16,6 +16,14 @@
|
||||
|
||||
package org.springframework.web.servlet.mvc.method.annotation;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.beans.PropertyEditorSupport;
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
@@ -40,6 +48,7 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletException;
|
||||
@@ -53,7 +62,6 @@ import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
|
||||
import org.springframework.aop.interceptor.SimpleTraceInterceptor;
|
||||
import org.springframework.aop.support.DefaultPointcutAdvisor;
|
||||
@@ -133,9 +141,6 @@ import org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionRes
|
||||
import org.springframework.web.servlet.mvc.method.annotation.support.ServletWebArgumentResolverAdapter;
|
||||
import org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver;
|
||||
import org.springframework.web.servlet.view.InternalResourceViewResolver;
|
||||
import org.springframework.web.util.NestedServletException;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* The origin of this test fixture is {@link ServletHandlerMethodTests} with tests in this class adapted to run
|
||||
@@ -771,18 +776,13 @@ public class ServletHandlerMethodTests {
|
||||
|
||||
@Test
|
||||
public void equivalentMappingsWithSameMethodName() throws Exception {
|
||||
initDispatcherServlet(ChildController.class, null);
|
||||
servlet.init(new MockServletConfig());
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/child/test");
|
||||
request.addParameter("childId", "100");
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
try {
|
||||
servlet.service(request, response);
|
||||
initDispatcherServlet(ChildController.class, null);
|
||||
fail("Expected 'method already mapped' error");
|
||||
}
|
||||
catch (NestedServletException ex) {
|
||||
assertTrue(ex.getCause() instanceof IllegalStateException);
|
||||
assertTrue(ex.getCause().getMessage().contains("doGet"));
|
||||
catch (BeanCreationException e) {
|
||||
assertTrue(e.getCause() instanceof IllegalStateException);
|
||||
assertTrue(e.getCause().getMessage().contains("Ambiguous mapping"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user