diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcChildContextConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcChildContextConfiguration.java index fc7c7a90d1f..d0d77a98283 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcChildContextConfiguration.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcChildContextConfiguration.java @@ -31,7 +31,6 @@ import org.springframework.beans.factory.BeanFactoryUtils; import org.springframework.beans.factory.HierarchicalBeanFactory; import org.springframework.beans.factory.ListableBeanFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.actuate.autoconfigure.ManagementWebSecurityAutoConfiguration.ManagementWebSecurityConfigurerAdapter; import org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping; import org.springframework.boot.actuate.endpoint.mvc.ManagementErrorEndpoint; @@ -83,9 +82,6 @@ public class EndpointWebMvcChildContextConfiguration { private static Log logger = LogFactory .getLog(EndpointWebMvcChildContextConfiguration.class); - @Value("${error.path:/error}") - private String errorPath = "/error"; - @Bean(name = DispatcherServletAutoConfiguration.DEFAULT_DISPATCHER_SERVLET_BEAN_NAME) public DispatcherServlet dispatcherServlet() { DispatcherServlet dispatcherServlet = new DispatcherServlet(); @@ -123,8 +119,9 @@ public class EndpointWebMvcChildContextConfiguration { * disabled. So we expose the same feature but only for machine endpoints. */ @Bean - public ManagementErrorEndpoint errorEndpoint(final ErrorAttributes errorAttributes) { - return new ManagementErrorEndpoint(this.errorPath, errorAttributes); + public ManagementErrorEndpoint errorEndpoint(ServerProperties serverProperties, + final ErrorAttributes errorAttributes) { + return new ManagementErrorEndpoint(serverProperties.getError().getPath(), errorAttributes); } /** @@ -208,9 +205,6 @@ public class EndpointWebMvcChildContextConfiguration { static class ServerCustomization implements EmbeddedServletContainerCustomizer, Ordered { - @Value("${error.path:/error}") - private String errorPath = "/error"; - @Autowired private ListableBeanFactory beanFactory; @@ -242,7 +236,7 @@ public class EndpointWebMvcChildContextConfiguration { // and add the management-specific bits container.setPort(this.managementServerProperties.getPort()); container.setAddress(this.managementServerProperties.getAddress()); - container.addErrorPages(new ErrorPage(this.errorPath)); + container.addErrorPages(new ErrorPage(this.server.getError().getPath())); } } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/BasicErrorController.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/BasicErrorController.java index 11b82f7d4f1..aadb01fa873 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/BasicErrorController.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/BasicErrorController.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -45,7 +45,7 @@ import org.springframework.web.servlet.ModelAndView; * @see ErrorProperties */ @Controller -@RequestMapping("${error.path:/error}") +@RequestMapping("${server.error.path:${error.path:/error}}") public class BasicErrorController extends AbstractErrorController { private final ErrorProperties errorProperties; diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ErrorMvcAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ErrorMvcAutoConfiguration.java index 6caa84d1ed0..4e3fe761fdc 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ErrorMvcAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ErrorMvcAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -75,9 +75,6 @@ import org.springframework.web.util.HtmlUtils; public class ErrorMvcAutoConfiguration implements EmbeddedServletContainerCustomizer, Ordered { - @Autowired - private ErrorProperties errorProperties; - @Autowired private ServerProperties properties; @@ -95,17 +92,17 @@ public class ErrorMvcAutoConfiguration implements EmbeddedServletContainerCustom @Bean @ConditionalOnMissingBean(value = ErrorController.class, search = SearchStrategy.CURRENT) public BasicErrorController basicErrorController(ErrorAttributes errorAttributes) { - return new BasicErrorController(errorAttributes, this.errorProperties); + return new BasicErrorController(errorAttributes, this.properties.getError()); } @Override public void customize(ConfigurableEmbeddedServletContainer container) { container.addErrorPages(new ErrorPage(this.properties.getServletPrefix() - + this.errorProperties.getPath())); + + this.properties.getError().getPath())); } @Configuration - @ConditionalOnProperty(prefix = "error.whitelabel", name = "enabled", matchIfMissing = true) + @ConditionalOnProperty(prefix = "server.error.whitelabel", name = "enabled", matchIfMissing = true) @Conditional(ErrorTemplateMissingCondition.class) protected static class WhitelabelErrorViewConfiguration { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ErrorProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ErrorProperties.java index c7974a841a2..265b6de8f02 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ErrorProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ErrorProperties.java @@ -16,7 +16,7 @@ package org.springframework.boot.autoconfigure.web; -import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.beans.factory.annotation.Value; /** * Configuration properties for web error handling. @@ -25,12 +25,12 @@ import org.springframework.boot.context.properties.ConfigurationProperties; * @author Stephane Nicoll * @since 1.3.0 */ -@ConfigurationProperties("error") public class ErrorProperties { /** * Path of the error controller. */ + @Value("${error.path:/error}") private String path = "/error"; /** diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java index e274303a831..5e185e4d6ba 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java @@ -96,6 +96,9 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer, */ private String displayName = "application"; + @NestedConfigurationProperty + private ErrorProperties error = new ErrorProperties(); + /** * Path of the main dispatcher servlet. */ @@ -328,6 +331,10 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer, this.session.setTimeout(sessionTimeout); } + public ErrorProperties getError() { + return this.error; + } + public Session getSession() { return this.session; } diff --git a/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json index 34296e3aa4f..b625c9a672f 100644 --- a/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -1,10 +1,24 @@ {"properties": [ + { + "name": "error.path", + "type": "java.lang.String", + "description": "Path of the error controller.", + "deprecation": { + "replacement": "server.error.path" + } + }, { "name": "multipart.enabled", "type": "java.lang.Boolean", "description": "Enable support of multi-part uploads.", "defaultValue": true }, + { + "name": "server.error.whitelabel.enabled", + "type": "java.lang.Boolean", + "description": "Enable the default error page displayed in browsers in case of a server error.", + "defaultValue": true + }, { "name": "spring.aop.auto", "type": "java.lang.Boolean", diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerDirectMockMvcTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerDirectMockMvcTests.java index 764ba535f83..7cc4717937f 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerDirectMockMvcTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerDirectMockMvcTests.java @@ -99,7 +99,7 @@ public class BasicErrorControllerDirectMockMvcTests { public void errorPageNotAvailableWithWhitelabelDisabled() throws Exception { setup((ConfigurableWebApplicationContext) new SpringApplication( WebMvcIncludedConfiguration.class).run("--server.port=0", - "--error.whitelabel.enabled=false")); + "--server.error.whitelabel.enabled=false")); this.thrown.expect(ServletException.class); this.mockMvc.perform(get("/error").accept(MediaType.TEXT_HTML)); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerIntegrationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerIntegrationTests.java index 6360b7a02b2..c5c33356503 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerIntegrationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerIntegrationTests.java @@ -95,7 +95,7 @@ public class BasicErrorControllerIntegrationTests { @Test @SuppressWarnings("rawtypes") public void testErrorForMachineClientTracePramamStacktrace() throws Exception { - load("--error.include-stacktrace=on-trace-param"); + load("--server.error.include-stacktrace=on-trace-param"); ResponseEntity entity = new TestRestTemplate().getForEntity( createUrl("?trace=true"), Map.class); assertErrorAttributes(entity.getBody(), "500", "" + "Internal Server Error", @@ -106,7 +106,7 @@ public class BasicErrorControllerIntegrationTests { @Test @SuppressWarnings("rawtypes") public void testErrorForMachineClientNoStacktrace() throws Exception { - load("--error.include-stacktrace=never"); + load("--server.error.include-stacktrace=never"); ResponseEntity entity = new TestRestTemplate().getForEntity( createUrl("?trace=true"), Map.class); assertErrorAttributes(entity.getBody(), "500", "" + "Internal Server Error", @@ -118,7 +118,7 @@ public class BasicErrorControllerIntegrationTests { @Test @SuppressWarnings("rawtypes") public void testErrorForMachineClientAlwaysStacktrace() throws Exception { - load("--error.include-stacktrace=always"); + load("--server.error.include-stacktrace=always"); ResponseEntity entity = new TestRestTemplate().getForEntity( createUrl("?trace=false"), Map.class); assertErrorAttributes(entity.getBody(), "500", "" + "Internal Server Error", diff --git a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc index 7b4baa42b3b..d55d8726b7a 100644 --- a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc +++ b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc @@ -139,8 +139,9 @@ content into your application; rather pick only the properties that you need. server.undertow.worker-threads= # number of worker threads # ERROR HANDLING ({sc-spring-boot-autoconfigure}/web/ErrorProperties.{sc-ext}[ErrorProperties]) - error.path=/error # the error path - error.include-stacktrace=never # when to include a stacktrace attribute (never/alway/on-trace-param) + server.error.path=/error # the error path + server.error.include-stacktrace=never # when to include a stacktrace attribute (never/alway/on-trace-param) + server.error.whitelabel.enabled=true # enable the default error page displayed in browsers in case of a server error # SPRING MVC ({sc-spring-boot-autoconfigure}/web/WebMvcProperties.{sc-ext}[WebMvcProperties]) spring.mvc.locale= # set fixed locale, e.g. en_UK diff --git a/spring-boot-docs/src/main/asciidoc/howto.adoc b/spring-boot-docs/src/main/asciidoc/howto.adoc index 43222d9a9aa..7031be4bf17 100644 --- a/spring-boot-docs/src/main/asciidoc/howto.adoc +++ b/spring-boot-docs/src/main/asciidoc/howto.adoc @@ -1744,7 +1744,7 @@ in the '`Production-ready features`' section. Spring Boot installs a '`whitelabel`' error page that you will see in browser client if you encounter a server error (machine clients consuming JSON and other media types should see a sensible response with the right error code). To switch it off you can set -`error.whitelabel.enabled=false`, but normally in addition or alternatively to that you +`server.error.whitelabel.enabled=false`, but normally in addition or alternatively to that you will want to add your own error page replacing the whitelabel one. Exactly how you do this depends on the templating technology that you are using. For example, if you are using Thymeleaf you would add an `error.html` template and if you are using FreeMarker you would diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/resources/application-endpoints.properties b/spring-boot-samples/spring-boot-sample-actuator/src/test/resources/application-endpoints.properties index 5c24a2ad93b..9803d5a6105 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/resources/application-endpoints.properties +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/resources/application-endpoints.properties @@ -1,3 +1,3 @@ -error.path: /oops +server.error.path: /oops management.context-path: /admin endpoints.health.sensitive: false \ No newline at end of file