@@ -272,12 +272,12 @@ public class DispatcherServlet extends FrameworkServlet {
272
272
/** Detect all ViewResolvers or just expect "viewResolver" bean? */
273
273
private boolean detectAllViewResolvers = true ;
274
274
275
- /** Perform cleanup of request attributes after include request? */
276
- private boolean cleanupAfterInclude = true ;
277
-
278
275
/** Throw a NoHandlerFoundException if no Handler was found to process this request? **/
279
276
private boolean throwExceptionIfNoHandlerFound = false ;
280
277
278
+ /** Perform cleanup of request attributes after include request? */
279
+ private boolean cleanupAfterInclude = true ;
280
+
281
281
/** MultipartResolver used by this servlet */
282
282
private MultipartResolver multipartResolver ;
283
283
@@ -413,12 +413,11 @@ public void setDetectAllViewResolvers(boolean detectAllViewResolvers) {
413
413
* Set whether to throw a NoHandlerFoundException when no Handler was found for this request.
414
414
* This exception can then be caught with a HandlerExceptionResolver or an
415
415
* {@code @ExceptionHandler} controller method.
416
- * <p>Note that if
417
- * {@link org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler}
418
- * is used, then requests will always be forwarded to the default servlet and
419
- * a NoHandlerFoundException would never be thrown in that case.
420
- * <p>Default is "false", meaning the DispatcherServlet sends a NOT_FOUND error
421
- * through the Servlet response.
416
+ * <p>Note that if {@link org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler}
417
+ * is used, then requests will always be forwarded to the default servlet and a
418
+ * NoHandlerFoundException would never be thrown in that case.
419
+ * <p>Default is "false", meaning the DispatcherServlet sends a NOT_FOUND error through the
420
+ * Servlet response.
422
421
* @since 4.0
423
422
*/
424
423
public void setThrowExceptionIfNoHandlerFound (boolean throwExceptionIfNoHandlerFound ) {
@@ -1111,10 +1110,10 @@ protected void noHandlerFound(HttpServletRequest request, HttpServletResponse re
1111
1110
pageNotFoundLogger .warn ("No mapping found for HTTP request with URI [" + getRequestUri (request ) +
1112
1111
"] in DispatcherServlet with name '" + getServletName () + "'" );
1113
1112
}
1114
- if (throwExceptionIfNoHandlerFound ) {
1115
- ServletServerHttpRequest req = new ServletServerHttpRequest (request );
1116
- throw new NoHandlerFoundException (req . getMethod (). name (),
1117
- req . getServletRequest ().getRequestURI (),req .getHeaders ());
1113
+ if (this . throwExceptionIfNoHandlerFound ) {
1114
+ ServletServerHttpRequest sshr = new ServletServerHttpRequest (request );
1115
+ throw new NoHandlerFoundException (
1116
+ sshr . getMethod (). name (), sshr . getServletRequest ().getRequestURI (), sshr .getHeaders ());
1118
1117
}
1119
1118
else {
1120
1119
response .sendError (HttpServletResponse .SC_NOT_FOUND );
0 commit comments