user3648971
user3648971

Reputation: 101

Servlet 3.0 without web.xml error-page javaconfig

In the web.xml file, error page as follows.

<error-page>
   <location>/WEB-INF/jsp/admin/ErrorPage.jsp</location>
</error-page>

without web.xml javaconfig convert

@Configuration
@EnableWebMvc
@ComponentScan("sg.ani.api.controller")
public class WebConfig extends WebMvcConfigurerAdapter{
}

override search no error page

How to javaconfig convert?

Upvotes: 1

Views: 1092

Answers (1)

george
george

Reputation: 3221

Create a class with the following:

@ControllerAdvice
public class ExceptionHandling {

  @ExceptionHandler(value=Exception.class)
  public String showErrorPage(){
    return "error";
  }
}

The @ControllerAdvice must be component-scanned so based on your config it must be somewhere in sg.ani.api.controller. This will catch all exceptions and direct them to the error page. So just create a new error page and you should be fine.

Upvotes: 2

Related Questions