Skip to content

Commit 7ed16a8

Browse files
committed
Register error pages in a consistent way regardless of the use of an embedded servlet container.
Details: https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-1.4-Release-Notes#errorpageregistry Addressed to #413 No functional changes.
1 parent 5e26ab5 commit 7ed16a8

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/main/java/ru/mystamps/web/support/spring/boot/ApplicationBootstrap.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
DispatcherServletContext.class,
3939
ThymeleafViewResolverInitializingBean.class,
4040
JettyServletContainerCustomizer.class,
41-
ErrorPagesServletContainerCustomizer.class
41+
ErrorPagesCustomizer.class
4242
})
4343
public class ApplicationBootstrap {
4444

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,22 @@
2020
import org.springframework.context.annotation.Configuration;
2121
import org.springframework.http.HttpStatus;
2222

23-
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
24-
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
2523
import org.springframework.boot.web.servlet.ErrorPage;
24+
import org.springframework.boot.web.servlet.ErrorPageRegistrar;
25+
import org.springframework.boot.web.servlet.ErrorPageRegistry;
2626

2727
import ru.mystamps.web.Url;
2828

2929
@Configuration
30-
public class ErrorPagesServletContainerCustomizer implements EmbeddedServletContainerCustomizer {
31-
30+
public class ErrorPagesCustomizer implements ErrorPageRegistrar {
31+
3232
@Override
33-
public void customize(ConfigurableEmbeddedServletContainer container) {
34-
container.addErrorPages(new ErrorPage(HttpStatus.FORBIDDEN, Url.FORBIDDEN_PAGE));
35-
container.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, Url.NOT_FOUND_PAGE));
36-
container.addErrorPages(new ErrorPage(Exception.class, Url.INTERNAL_ERROR_PAGE));
33+
public void registerErrorPages(ErrorPageRegistry registry) {
34+
registry.addErrorPages(
35+
new ErrorPage(HttpStatus.FORBIDDEN, Url.FORBIDDEN_PAGE),
36+
new ErrorPage(HttpStatus.NOT_FOUND, Url.NOT_FOUND_PAGE),
37+
new ErrorPage(Exception.class, Url.INTERNAL_ERROR_PAGE)
38+
);
3739
}
3840

3941
}

0 commit comments

Comments
 (0)