Commit b2c3e7e2 authored by Stephane Nicoll's avatar Stephane Nicoll

Rename error.* properties to server.error.*

Closes gh-4050
parent 4b138917
...@@ -31,7 +31,6 @@ import org.springframework.beans.factory.BeanFactoryUtils; ...@@ -31,7 +31,6 @@ import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.beans.factory.HierarchicalBeanFactory; import org.springframework.beans.factory.HierarchicalBeanFactory;
import org.springframework.beans.factory.ListableBeanFactory; import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.beans.factory.annotation.Autowired; 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.autoconfigure.ManagementWebSecurityAutoConfiguration.ManagementWebSecurityConfigurerAdapter;
import org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping; import org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping;
import org.springframework.boot.actuate.endpoint.mvc.ManagementErrorEndpoint; import org.springframework.boot.actuate.endpoint.mvc.ManagementErrorEndpoint;
...@@ -83,9 +82,6 @@ public class EndpointWebMvcChildContextConfiguration { ...@@ -83,9 +82,6 @@ public class EndpointWebMvcChildContextConfiguration {
private static Log logger = LogFactory private static Log logger = LogFactory
.getLog(EndpointWebMvcChildContextConfiguration.class); .getLog(EndpointWebMvcChildContextConfiguration.class);
@Value("${error.path:/error}")
private String errorPath = "/error";
@Bean(name = DispatcherServletAutoConfiguration.DEFAULT_DISPATCHER_SERVLET_BEAN_NAME) @Bean(name = DispatcherServletAutoConfiguration.DEFAULT_DISPATCHER_SERVLET_BEAN_NAME)
public DispatcherServlet dispatcherServlet() { public DispatcherServlet dispatcherServlet() {
DispatcherServlet dispatcherServlet = new DispatcherServlet(); DispatcherServlet dispatcherServlet = new DispatcherServlet();
...@@ -123,8 +119,9 @@ public class EndpointWebMvcChildContextConfiguration { ...@@ -123,8 +119,9 @@ public class EndpointWebMvcChildContextConfiguration {
* disabled. So we expose the same feature but only for machine endpoints. * disabled. So we expose the same feature but only for machine endpoints.
*/ */
@Bean @Bean
public ManagementErrorEndpoint errorEndpoint(final ErrorAttributes errorAttributes) { public ManagementErrorEndpoint errorEndpoint(ServerProperties serverProperties,
return new ManagementErrorEndpoint(this.errorPath, errorAttributes); final ErrorAttributes errorAttributes) {
return new ManagementErrorEndpoint(serverProperties.getError().getPath(), errorAttributes);
} }
/** /**
...@@ -208,9 +205,6 @@ public class EndpointWebMvcChildContextConfiguration { ...@@ -208,9 +205,6 @@ public class EndpointWebMvcChildContextConfiguration {
static class ServerCustomization implements EmbeddedServletContainerCustomizer, static class ServerCustomization implements EmbeddedServletContainerCustomizer,
Ordered { Ordered {
@Value("${error.path:/error}")
private String errorPath = "/error";
@Autowired @Autowired
private ListableBeanFactory beanFactory; private ListableBeanFactory beanFactory;
...@@ -242,7 +236,7 @@ public class EndpointWebMvcChildContextConfiguration { ...@@ -242,7 +236,7 @@ public class EndpointWebMvcChildContextConfiguration {
// and add the management-specific bits // and add the management-specific bits
container.setPort(this.managementServerProperties.getPort()); container.setPort(this.managementServerProperties.getPort());
container.setAddress(this.managementServerProperties.getAddress()); container.setAddress(this.managementServerProperties.getAddress());
container.addErrorPages(new ErrorPage(this.errorPath)); container.addErrorPages(new ErrorPage(this.server.getError().getPath()));
} }
} }
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -45,7 +45,7 @@ import org.springframework.web.servlet.ModelAndView; ...@@ -45,7 +45,7 @@ import org.springframework.web.servlet.ModelAndView;
* @see ErrorProperties * @see ErrorProperties
*/ */
@Controller @Controller
@RequestMapping("${error.path:/error}") @RequestMapping("${server.error.path:${error.path:/error}}")
public class BasicErrorController extends AbstractErrorController { public class BasicErrorController extends AbstractErrorController {
private final ErrorProperties errorProperties; private final ErrorProperties errorProperties;
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -75,9 +75,6 @@ import org.springframework.web.util.HtmlUtils; ...@@ -75,9 +75,6 @@ import org.springframework.web.util.HtmlUtils;
public class ErrorMvcAutoConfiguration implements EmbeddedServletContainerCustomizer, public class ErrorMvcAutoConfiguration implements EmbeddedServletContainerCustomizer,
Ordered { Ordered {
@Autowired
private ErrorProperties errorProperties;
@Autowired @Autowired
private ServerProperties properties; private ServerProperties properties;
...@@ -95,17 +92,17 @@ public class ErrorMvcAutoConfiguration implements EmbeddedServletContainerCustom ...@@ -95,17 +92,17 @@ public class ErrorMvcAutoConfiguration implements EmbeddedServletContainerCustom
@Bean @Bean
@ConditionalOnMissingBean(value = ErrorController.class, search = SearchStrategy.CURRENT) @ConditionalOnMissingBean(value = ErrorController.class, search = SearchStrategy.CURRENT)
public BasicErrorController basicErrorController(ErrorAttributes errorAttributes) { public BasicErrorController basicErrorController(ErrorAttributes errorAttributes) {
return new BasicErrorController(errorAttributes, this.errorProperties); return new BasicErrorController(errorAttributes, this.properties.getError());
} }
@Override @Override
public void customize(ConfigurableEmbeddedServletContainer container) { public void customize(ConfigurableEmbeddedServletContainer container) {
container.addErrorPages(new ErrorPage(this.properties.getServletPrefix() container.addErrorPages(new ErrorPage(this.properties.getServletPrefix()
+ this.errorProperties.getPath())); + this.properties.getError().getPath()));
} }
@Configuration @Configuration
@ConditionalOnProperty(prefix = "error.whitelabel", name = "enabled", matchIfMissing = true) @ConditionalOnProperty(prefix = "server.error.whitelabel", name = "enabled", matchIfMissing = true)
@Conditional(ErrorTemplateMissingCondition.class) @Conditional(ErrorTemplateMissingCondition.class)
protected static class WhitelabelErrorViewConfiguration { protected static class WhitelabelErrorViewConfiguration {
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
package org.springframework.boot.autoconfigure.web; 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. * Configuration properties for web error handling.
...@@ -25,12 +25,12 @@ import org.springframework.boot.context.properties.ConfigurationProperties; ...@@ -25,12 +25,12 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
* @author Stephane Nicoll * @author Stephane Nicoll
* @since 1.3.0 * @since 1.3.0
*/ */
@ConfigurationProperties("error")
public class ErrorProperties { public class ErrorProperties {
/** /**
* Path of the error controller. * Path of the error controller.
*/ */
@Value("${error.path:/error}")
private String path = "/error"; private String path = "/error";
/** /**
......
...@@ -96,6 +96,9 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer, ...@@ -96,6 +96,9 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer,
*/ */
private String displayName = "application"; private String displayName = "application";
@NestedConfigurationProperty
private ErrorProperties error = new ErrorProperties();
/** /**
* Path of the main dispatcher servlet. * Path of the main dispatcher servlet.
*/ */
...@@ -328,6 +331,10 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer, ...@@ -328,6 +331,10 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer,
this.session.setTimeout(sessionTimeout); this.session.setTimeout(sessionTimeout);
} }
public ErrorProperties getError() {
return this.error;
}
public Session getSession() { public Session getSession() {
return this.session; return this.session;
} }
......
{"properties": [ {"properties": [
{
"name": "error.path",
"type": "java.lang.String",
"description": "Path of the error controller.",
"deprecation": {
"replacement": "server.error.path"
}
},
{ {
"name": "multipart.enabled", "name": "multipart.enabled",
"type": "java.lang.Boolean", "type": "java.lang.Boolean",
"description": "Enable support of multi-part uploads.", "description": "Enable support of multi-part uploads.",
"defaultValue": true "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", "name": "spring.aop.auto",
"type": "java.lang.Boolean", "type": "java.lang.Boolean",
......
...@@ -99,7 +99,7 @@ public class BasicErrorControllerDirectMockMvcTests { ...@@ -99,7 +99,7 @@ public class BasicErrorControllerDirectMockMvcTests {
public void errorPageNotAvailableWithWhitelabelDisabled() throws Exception { public void errorPageNotAvailableWithWhitelabelDisabled() throws Exception {
setup((ConfigurableWebApplicationContext) new SpringApplication( setup((ConfigurableWebApplicationContext) new SpringApplication(
WebMvcIncludedConfiguration.class).run("--server.port=0", WebMvcIncludedConfiguration.class).run("--server.port=0",
"--error.whitelabel.enabled=false")); "--server.error.whitelabel.enabled=false"));
this.thrown.expect(ServletException.class); this.thrown.expect(ServletException.class);
this.mockMvc.perform(get("/error").accept(MediaType.TEXT_HTML)); this.mockMvc.perform(get("/error").accept(MediaType.TEXT_HTML));
......
...@@ -95,7 +95,7 @@ public class BasicErrorControllerIntegrationTests { ...@@ -95,7 +95,7 @@ public class BasicErrorControllerIntegrationTests {
@Test @Test
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public void testErrorForMachineClientTracePramamStacktrace() throws Exception { public void testErrorForMachineClientTracePramamStacktrace() throws Exception {
load("--error.include-stacktrace=on-trace-param"); load("--server.error.include-stacktrace=on-trace-param");
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity( ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
createUrl("?trace=true"), Map.class); createUrl("?trace=true"), Map.class);
assertErrorAttributes(entity.getBody(), "500", "" + "Internal Server Error", assertErrorAttributes(entity.getBody(), "500", "" + "Internal Server Error",
...@@ -106,7 +106,7 @@ public class BasicErrorControllerIntegrationTests { ...@@ -106,7 +106,7 @@ public class BasicErrorControllerIntegrationTests {
@Test @Test
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public void testErrorForMachineClientNoStacktrace() throws Exception { public void testErrorForMachineClientNoStacktrace() throws Exception {
load("--error.include-stacktrace=never"); load("--server.error.include-stacktrace=never");
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity( ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
createUrl("?trace=true"), Map.class); createUrl("?trace=true"), Map.class);
assertErrorAttributes(entity.getBody(), "500", "" + "Internal Server Error", assertErrorAttributes(entity.getBody(), "500", "" + "Internal Server Error",
...@@ -118,7 +118,7 @@ public class BasicErrorControllerIntegrationTests { ...@@ -118,7 +118,7 @@ public class BasicErrorControllerIntegrationTests {
@Test @Test
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public void testErrorForMachineClientAlwaysStacktrace() throws Exception { public void testErrorForMachineClientAlwaysStacktrace() throws Exception {
load("--error.include-stacktrace=always"); load("--server.error.include-stacktrace=always");
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity( ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
createUrl("?trace=false"), Map.class); createUrl("?trace=false"), Map.class);
assertErrorAttributes(entity.getBody(), "500", "" + "Internal Server Error", assertErrorAttributes(entity.getBody(), "500", "" + "Internal Server Error",
......
...@@ -139,8 +139,9 @@ content into your application; rather pick only the properties that you need. ...@@ -139,8 +139,9 @@ content into your application; rather pick only the properties that you need.
server.undertow.worker-threads= # number of worker threads server.undertow.worker-threads= # number of worker threads
# ERROR HANDLING ({sc-spring-boot-autoconfigure}/web/ErrorProperties.{sc-ext}[ErrorProperties]) # ERROR HANDLING ({sc-spring-boot-autoconfigure}/web/ErrorProperties.{sc-ext}[ErrorProperties])
error.path=/error # the error path server.error.path=/error # the error path
error.include-stacktrace=never # when to include a stacktrace attribute (never/alway/on-trace-param) 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 ({sc-spring-boot-autoconfigure}/web/WebMvcProperties.{sc-ext}[WebMvcProperties])
spring.mvc.locale= # set fixed locale, e.g. en_UK spring.mvc.locale= # set fixed locale, e.g. en_UK
......
...@@ -1744,7 +1744,7 @@ in the '`Production-ready features`' section. ...@@ -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 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 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 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 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 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 Thymeleaf you would add an `error.html` template and if you are using FreeMarker you would
......
error.path: /oops server.error.path: /oops
management.context-path: /admin management.context-path: /admin
endpoints.health.sensitive: false endpoints.health.sensitive: false
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment