SPR-8782 Raise helpful error when RedirectAttributes is used with old infrastructure classes.
This commit is contained in:
parent
5a6980b78b
commit
1164f5a9fc
|
|
@ -138,6 +138,7 @@ import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping;
|
|||
import org.springframework.web.servlet.mvc.AbstractController;
|
||||
import org.springframework.web.servlet.mvc.multiaction.InternalPathMethodNameResolver;
|
||||
import org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping;
|
||||
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||
import org.springframework.web.servlet.view.InternalResourceViewResolver;
|
||||
import org.springframework.web.util.NestedServletException;
|
||||
|
||||
|
|
@ -1910,6 +1911,17 @@ public class ServletAnnotationControllerTests {
|
|||
assertEquals("homeJson", response.getContentAsString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void redirectAttribute() throws Exception {
|
||||
initServlet(RedirectAttributesController.class);
|
||||
try {
|
||||
servlet.service(new MockHttpServletRequest("GET", "/"), new MockHttpServletResponse());
|
||||
}
|
||||
catch (NestedServletException ex) {
|
||||
assertTrue(ex.getMessage().contains("not assignable from the actual model"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Controllers
|
||||
|
|
@ -3207,4 +3219,12 @@ public class ServletAnnotationControllerTests {
|
|||
}
|
||||
}
|
||||
|
||||
@Controller
|
||||
static class RedirectAttributesController {
|
||||
|
||||
@RequestMapping(value = "/")
|
||||
public void handle(RedirectAttributes redirectAttrs) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@ import java.util.Set;
|
|||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.BridgeMethodResolver;
|
||||
|
|
@ -313,8 +312,13 @@ public class HandlerMethodInvoker {
|
|||
args[i] = resolveDefaultValue(defaultValue);
|
||||
}
|
||||
else {
|
||||
Class paramType = methodParam.getParameterType();
|
||||
Class<?> paramType = methodParam.getParameterType();
|
||||
if (Model.class.isAssignableFrom(paramType) || Map.class.isAssignableFrom(paramType)) {
|
||||
if (!paramType.isAssignableFrom(implicitModel.getClass())) {
|
||||
throw new IllegalStateException("Argument [" + paramType.getSimpleName() + "] is of type " +
|
||||
"Model or Map but is not assignable from the actual model. You may need to switch " +
|
||||
"newer MVC infrastructure classes to use this argument.");
|
||||
}
|
||||
args[i] = implicitModel;
|
||||
}
|
||||
else if (SessionStatus.class.isAssignableFrom(paramType)) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue