Set throwExceptionIfNoHandlerFound=true and deprecate
Closes gh-29491
This commit is contained in:
@@ -305,7 +305,7 @@ public class DispatcherServlet extends FrameworkServlet {
|
||||
private boolean detectAllViewResolvers = true;
|
||||
|
||||
/** Throw a NoHandlerFoundException if no Handler was found to process this request? *.*/
|
||||
private boolean throwExceptionIfNoHandlerFound = false;
|
||||
private boolean throwExceptionIfNoHandlerFound = true;
|
||||
|
||||
/** Perform cleanup of request attributes after include request?. */
|
||||
private boolean cleanupAfterInclude = true;
|
||||
@@ -467,7 +467,12 @@ public class DispatcherServlet extends FrameworkServlet {
|
||||
* <p>Default is "false", meaning the DispatcherServlet sends a NOT_FOUND error through the
|
||||
* Servlet response.
|
||||
* @since 4.0
|
||||
* @deprecated as of 6.1 this property is set to {@code true} by default, and
|
||||
* should not need to be customized; in effect, {@link DispatcherServlet}
|
||||
* should always raise {@link NoHandlerFoundException} and allow it to be
|
||||
* handled through a {@link HandlerExceptionResolver}.
|
||||
*/
|
||||
@Deprecated(since = "6.1", forRemoval = true)
|
||||
public void setThrowExceptionIfNoHandlerFound(boolean throwExceptionIfNoHandlerFound) {
|
||||
this.throwExceptionIfNoHandlerFound = throwExceptionIfNoHandlerFound;
|
||||
}
|
||||
|
||||
@@ -150,20 +150,26 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext {
|
||||
registerSingleton("myServlet", MyServlet.class);
|
||||
|
||||
pvs = new MutablePropertyValues();
|
||||
pvs.add("order", "1");
|
||||
pvs.add("order", "2");
|
||||
pvs.add("exceptionMappings",
|
||||
"java.lang.IllegalAccessException=failed2\n" +
|
||||
"ServletRequestBindingException=failed3");
|
||||
pvs.add("defaultErrorView", "failed0");
|
||||
registerSingleton("exceptionResolver1", SimpleMappingExceptionResolver.class, pvs);
|
||||
registerSingleton("exceptionResolver2", SimpleMappingExceptionResolver.class, pvs);
|
||||
|
||||
pvs = new MutablePropertyValues();
|
||||
pvs.add("order", "0");
|
||||
pvs.add("order", "1");
|
||||
pvs.add("exceptionMappings", "java.lang.Exception=failed1");
|
||||
pvs.add("mappedHandlers", ManagedList.of(new RuntimeBeanReference("anotherLocaleHandler")));
|
||||
pvs.add("defaultStatusCode", "500");
|
||||
pvs.add("defaultErrorView", "failed2");
|
||||
registerSingleton("handlerExceptionResolver", SimpleMappingExceptionResolver.class, pvs);
|
||||
registerSingleton("exceptionResolver1", SimpleMappingExceptionResolver.class, pvs);
|
||||
|
||||
pvs = new MutablePropertyValues();
|
||||
pvs.add("order", "0");
|
||||
pvs.add("exceptionMappings", "org.springframework.web.servlet.NoHandlerFoundException=notFound");
|
||||
pvs.add("defaultStatusCode", "404");
|
||||
registerSingleton("exceptionResolver0", SimpleMappingExceptionResolver.class, pvs);
|
||||
|
||||
registerSingleton("multipartResolver", MockMultipartResolver.class);
|
||||
registerSingleton("testListener", TestApplicationListener.class);
|
||||
|
||||
@@ -591,7 +591,6 @@ public class DispatcherServletTests {
|
||||
DispatcherServlet complexDispatcherServlet = new DispatcherServlet();
|
||||
complexDispatcherServlet.setContextClass(SimpleWebApplicationContext.class);
|
||||
complexDispatcherServlet.setNamespace("test");
|
||||
complexDispatcherServlet.setThrowExceptionIfNoHandlerFound(true);
|
||||
complexDispatcherServlet.init(new MockServletConfig(getServletContext(), "complex"));
|
||||
|
||||
MockHttpServletRequest request = new MockHttpServletRequest(getServletContext(), "GET", "/unknown");
|
||||
|
||||
Reference in New Issue
Block a user