i wish to have custom 404 error page .I have velocity in my classpath but I don't want to use velocity view resolver Below is my code
@EnableAutoConfiguration(exclude={VelocityAutoConfiguration.class})
@ComponentScan
public class Application {
Properties props = new Properties();
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
i am not able to redirect all the 404 to my some html in resource directory.
Please assist
P.S It work if i am use velocityresolver and have error.vm in template directory.
Thanks ans regards
We first need to create a custom HTML error page. If we save this file in resources/templates directory, it'll automatically be picked up by the default Spring Boot's BasicErrorController. We can be more specific by naming the file with the HTTP status code we want it used e.g. saving the file as 404.
enabled to false . Another way of disabling the WhiteLabel Error is excluding the ErrorMvcAutoConfiguration . Alternatively, the exclusion can be done in an annotation. When the WhiteLabel Error Page is disabled and no custom error page is provided, the web server's error page (Tomcat, Jetty) is shown.
You can provide a EmbeddedServletContainerCustomizer
and add your (e.g. static) error pages there. See Error Handling in the spring boot docs. E.g:
@Bean
public EmbeddedServletContainerCustomizer containerCustomizer() {
return new EmbeddedServletContainerCustomizer() {
@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
container.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/404.html"));
}
};
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With