Top Description Fields Constructors Methods
org.springframework.web.servlet

public Class NoHandlerFoundException

extends ServletException
implements ErrorResponse
Class Inheritance
All Implemented Interfaces
org.springframework.web.ErrorResponse
Annotations
@SuppressWarnings:serial
Imports
jakarta.servlet.ServletException, jakarta.servlet.http.HttpServletRequest, .HttpServletResponse, org.springframework.http.HttpHeaders, .HttpStatus, .HttpStatusCode, .ProblemDetail, org.springframework.web.ErrorResponse

By default, when the DispatcherServlet can't find a handler for a request it sends a 404 response. However, if its property "throwExceptionIfNoHandlerFound" is set to true this exception is raised and may be handled with a configured HandlerExceptionResolver.
Author
Brian Clozel
Since
4.0
See Also
DispatcherServlet#setThrowExceptionIfNoHandlerFound(boolean), DispatcherServlet#noHandlerFound(HttpServletRequest, HttpServletResponse)

Field Summary

Modifier and TypeField and Description
private final ProblemDetail
private final String
private final HttpHeaders
private final String

Constructor Summary

AccessConstructor and Description
public
NoHandlerFoundException(String
the HTTP method
httpMethod
,
String
the HTTP request URL
requestURL
,
HttpHeaders
the HTTP request headers
headers
)

Constructor for NoHandlerFoundException.

Method Summary

Modifier and TypeMethod and Description
public ProblemDetail
getBody()

Implements org.springframework.web.ErrorResponse.getBody.

Return the body for the response, formatted as an RFC 7807 ProblemDetail whose status should match the response status.

public HttpHeaders
getHeaders()

Overrides default org.springframework.web.ErrorResponse.getHeaders.

Return headers to use for the response.

public String
public HttpHeaders
getRequestHeaders()

Return the headers of the request.

public String
public HttpStatusCode
getStatusCode()

Implements org.springframework.web.ErrorResponse.getStatusCode.

Return the HTTP status code to use for the response.

Inherited from jakarta.servlet.ServletException:
getRootCause

Field Detail

bodyback to summary
private final ProblemDetail body
httpMethodback to summary
private final String httpMethod
requestHeadersback to summary
private final HttpHeaders requestHeaders
requestURLback to summary
private final String requestURL

Constructor Detail

NoHandlerFoundExceptionback to summary
public NoHandlerFoundException(String httpMethod, String requestURL, HttpHeaders headers)

Constructor for NoHandlerFoundException.

Parameters
httpMethod:String

the HTTP method

requestURL:String

the HTTP request URL

headers:HttpHeaders

the HTTP request headers

Method Detail

getBodyback to summary
public ProblemDetail getBody()

Implements org.springframework.web.ErrorResponse.getBody.

Doc from org.springframework.web.ErrorResponse.getBody.

Return the body for the response, formatted as an RFC 7807 ProblemDetail whose status should match the response status.

Annotations
@Override
getHeadersback to summary
public HttpHeaders getHeaders()

Overrides default org.springframework.web.ErrorResponse.getHeaders.

Return headers to use for the response.

Note

As of 6.0 this method overlaps with ErrorResponse#getHeaders() and therefore no longer returns request headers. Use getRequestHeaders() instead for request headers.

Annotations
@Override
getHttpMethodback to summary
public String getHttpMethod()
getRequestHeadersback to summary
public HttpHeaders getRequestHeaders()

Return the headers of the request.

Since
6.0.3
getRequestURLback to summary
public String getRequestURL()
getStatusCodeback to summary
public HttpStatusCode getStatusCode()

Implements org.springframework.web.ErrorResponse.getStatusCode.

Doc from org.springframework.web.ErrorResponse.getStatusCode.

Return the HTTP status code to use for the response.

Annotations
@Override