spring-boot: Spring not throwing NoHandlerFoundException anymore
After 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?
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 3
- Comments: 16 (7 by maintainers)
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.