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;
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()));
}
}
......
/*
* 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;
......
/*
* 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 {
......
......@@ -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";
/**
......
......@@ -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;
}
......
{"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",
......
......@@ -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));
......
......@@ -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<Map> 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<Map> 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<Map> entity = new TestRestTemplate().getForEntity(
createUrl("?trace=false"), Map.class);
assertErrorAttributes(entity.getBody(), "500", "" + "Internal Server Error",
......
......@@ -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
......
......@@ -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
......
error.path: /oops
server.error.path: /oops
management.context-path: /admin
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