Spring not throwing NoHandlerFoundException anymore
See original GitHub issueAfter we upgraded from Spring Boot 1.4.0 to 1.5.3 our web application does not throw the NoHandlerFoundException anymore. Configuration looks like the following:
in application.properties:
spring.mvc.throw-exception-if-no-handler-found=true
spring.resources.add-mappings=false
the corresponding exception controller:
@ControllerAdvice
@EnableWebMvc
public class ExceptionController
{
// works
@ExceptionHandler(AccessDeniedException.class)
public String handleAccessDeniedException(AccessDeniedException ex, HttpServletRequest request) {
return "403";
}
// doesn't work anymore
@ExceptionHandler(NoHandlerFoundException.class)
public String handleNotFoundError(NoHandlerFoundException ex, HttpServletRequest request) {
return "404";
}
}
We had no problems with Spring 1.4.0 but it stopped working in 1.5.3. Why is the exception not thrown anymore?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:16 (7 by maintainers)
Top Results From Across the Web
Custom exception handler for NoHandlerFoundException is ...
Is there an option for custom exception handling without @EnableWebMvc , because it overrides Spring configurations which are declared inside ...
Read more >Enhance exception handling when building RESTful API with ...
First one sets Spring to throw NoHandlerFoundException exception, which we can easily catch later on to generate a proper response.
Read more >Spring REST Error Handling Example - Mkyong.com
A controller, if a book id is not found, throws the above BookNotFoundException. BookController.java. package com.mkyong; //.
Read more >org.springframework.web.servlet.NoHandlerFoundException ...
No handler found -> set appropriate HTTP response status. * @param request current HTTP request * @param response current HTTP response * @throws...
Read more >Spring Boot Reference Guide
Spring Boot does not require any special tools integration, ... When the application is restarted, the restart classloader is thrown away and a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

While preparing a sample application we’ve found the culprit:
Replacing the URl pattern with the subfolder containing the static resources
spring.mvc.throw-exception-if-no-handler-found=truehave the desired effect. Thank you.You’re mapping everything with your static path pattern, so this behavior is expected. For further questions, please use StackOverflow.