• Adding @ResponseStatus annotation enables mapping custom exceptions with default spring status codes
  • ResponseStatusExceptionResolver automatically handles all thrown exceptions

Default Exception Handling Status Codes

Example: Status Code Mapping to Custom Exception

Configure Custom Error Page in Spring MVC

  • By default, Spring MVC will raise an exception while trying to access unauthorized resources. Such exceptions should be handled correctly by customizing error page configuration in Spring MVC
  • It is also possible to configure custom error pages using Java configuration with the help of @EnableWebSecurity annotation and WebSecurityConfigurerAdapter

XML configuration

Note: If an unauthorized user try to access a page then response will be redirected to “/my-error-page"