Skip to content

Commit 3becdc7

Browse files
committed
Move server.error properties to spring.web.error
Closes gh-48201
1 parent 2b30632 commit 3becdc7

File tree

37 files changed

+161
-125
lines changed

37 files changed

+161
-125
lines changed

core/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebProperties.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.jspecify.annotations.Nullable;
2525

2626
import org.springframework.boot.context.properties.ConfigurationProperties;
27+
import org.springframework.boot.context.properties.NestedConfigurationProperty;
2728
import org.springframework.boot.context.properties.PropertyMapper;
2829
import org.springframework.boot.convert.DurationUnit;
2930
import org.springframework.http.CacheControl;
@@ -50,6 +51,9 @@ public class WebProperties {
5051

5152
private final Resources resources = new Resources();
5253

54+
@NestedConfigurationProperty
55+
private final ErrorProperties error = new ErrorProperties();
56+
5357
public @Nullable Locale getLocale() {
5458
return this.locale;
5559
}
@@ -66,6 +70,10 @@ public void setLocaleResolver(LocaleResolver localeResolver) {
6670
this.localeResolver = localeResolver;
6771
}
6872

73+
public ErrorProperties getError() {
74+
return this.error;
75+
}
76+
6977
public Resources getResources() {
7078
return this.resources;
7179
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
defaults.spring.template.provider.cache=false
2+
defaults.spring.web.error.include-binding-errors=always
3+
defaults.spring.web.error.include-message=always
4+
defaults.spring.web.error.include-stacktrace=always
25
defaults.spring.web.resources.cache.period=0
36
defaults.spring.web.resources.chain.cache=false

documentation/spring-boot-docs/src/docs/antora/modules/how-to/pages/spring-mvc.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ For more detail, see the following sections:
247247

248248
Spring Boot installs a '`whitelabel`' error page that you see in a 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).
249249

250-
NOTE: Set `server.error.whitelabel.enabled=false` to switch the default error page off.
250+
NOTE: Set configprop:spring.web.error.whitelabel.enabled[] to `false` to switch the default error page off.
251251
Doing so restores the default of the servlet container that you are using.
252252
Note that Spring Boot still tries to resolve the error view, so you should probably add your own error page rather than disabling it completely.
253253

documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/web/reactive.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ Usually, you would define the properties in your `application.properties` or `ap
325325
Common server settings include:
326326

327327
* Network settings: Listen port for incoming HTTP requests (`server.port`), interface address to bind to (`server.address`), and so on.
328-
* Error management: Location of the error page (`server.error.path`) and so on.
328+
* Error management: Location of the error page (configprop:spring.web.error.path[]) and so on.
329329
* xref:how-to:webserver.adoc#howto.webserver.configure-ssl[SSL]
330330
* xref:how-to:webserver.adoc#howto.webserver.enable-response-compression[HTTP compression]
331331

documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/web/servlet.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ Common server settings include:
636636

637637
* Network settings: Listen port for incoming HTTP requests (`server.port`), interface address to bind to (`server.address`), and so on.
638638
* Session settings: Whether the session is persistent (`server.servlet.session.persistent`), session timeout (`server.servlet.session.timeout`), location of session data (`server.servlet.session.store-dir`), and session-cookie configuration (`server.servlet.session.cookie.*`).
639-
* Error management: Location of the error page (`server.error.path`) and so on.
639+
* Error management: Location of the error page (configprop:spring.web.error.path[]) and so on.
640640
* xref:how-to:webserver.adoc#howto.webserver.configure-ssl[SSL]
641641
* xref:how-to:webserver.adoc#howto.webserver.enable-response-compression[HTTP compression]
642642

integration-test/spring-boot-actuator-integration-tests/src/test/java/org/springframework/boot/actuate/endpoint/web/annotation/AbstractWebEndpointIntegrationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ private void load(Consumer<T> contextCustomizer, String endpointPath,
706706
contextCustomizer.accept(applicationContext);
707707
Map<String, Object> properties = new HashMap<>();
708708
properties.put("endpointPath", endpointPath);
709-
properties.put("server.error.include-message", "always");
709+
properties.put("spring.web.error.include-message", "always");
710710
applicationContext.getEnvironment().getPropertySources().addLast(new MapPropertySource("test", properties));
711711
applicationContext.refresh();
712712
try {

module/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfigurationTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,7 @@ LiveReloadServer liveReloadServer() {
286286
}
287287

288288
@Configuration(proxyBeanMethods = false)
289-
@Import({ TomcatServletWebServerAutoConfiguration.class, LocalDevToolsAutoConfiguration.class,
290-
WebProperties.class })
289+
@Import({ TomcatServletWebServerAutoConfiguration.class, LocalDevToolsAutoConfiguration.class })
291290
static class WebResourcesConfig {
292291

293292
}

module/spring-boot-tomcat/src/main/java/org/springframework/boot/tomcat/autoconfigure/TomcatWebServerConfiguration.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
2222
import org.springframework.boot.autoconfigure.condition.ConditionalOnNotWarDeployment;
2323
import org.springframework.boot.autoconfigure.condition.ConditionalOnThreading;
24+
import org.springframework.boot.autoconfigure.web.WebProperties;
25+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
2426
import org.springframework.boot.thread.Threading;
2527
import org.springframework.boot.tomcat.autoconfigure.reactive.TomcatReactiveWebServerAutoConfiguration;
2628
import org.springframework.boot.tomcat.autoconfigure.servlet.TomcatServletWebServerAutoConfiguration;
@@ -39,12 +41,13 @@
3941
*/
4042
@ConditionalOnNotWarDeployment
4143
@Configuration(proxyBeanMethods = false)
44+
@EnableConfigurationProperties(WebProperties.class)
4245
public class TomcatWebServerConfiguration {
4346

4447
@Bean
4548
TomcatWebServerFactoryCustomizer tomcatWebServerFactoryCustomizer(Environment environment,
46-
ServerProperties serverProperties, TomcatServerProperties tomcatProperties) {
47-
return new TomcatWebServerFactoryCustomizer(environment, serverProperties, tomcatProperties);
49+
ServerProperties serverProperties, TomcatServerProperties tomcatProperties, WebProperties webProperties) {
50+
return new TomcatWebServerFactoryCustomizer(environment, serverProperties, tomcatProperties, webProperties);
4851
}
4952

5053
@Bean

module/spring-boot-tomcat/src/main/java/org/springframework/boot/tomcat/autoconfigure/TomcatWebServerFactoryCustomizer.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
import org.springframework.boot.autoconfigure.web.ErrorProperties;
3636
import org.springframework.boot.autoconfigure.web.ErrorProperties.IncludeAttribute;
37+
import org.springframework.boot.autoconfigure.web.WebProperties;
3738
import org.springframework.boot.cloud.CloudPlatform;
3839
import org.springframework.boot.context.properties.PropertyMapper;
3940
import org.springframework.boot.tomcat.ConfigurableTomcatWebServerFactory;
@@ -77,11 +78,14 @@ public class TomcatWebServerFactoryCustomizer
7778

7879
private final TomcatServerProperties tomcatProperties;
7980

81+
private final WebProperties webProperties;
82+
8083
public TomcatWebServerFactoryCustomizer(Environment environment, ServerProperties serverProperties,
81-
TomcatServerProperties tomcatProperties) {
84+
TomcatServerProperties tomcatProperties, WebProperties webProperties) {
8285
this.environment = environment;
8386
this.serverProperties = serverProperties;
8487
this.tomcatProperties = tomcatProperties;
88+
this.webProperties = webProperties;
8589
}
8690

8791
@Override
@@ -161,7 +165,7 @@ public void customize(ConfigurableTomcatWebServerFactory factory) {
161165
.as((enable) -> !enable)
162166
.to(factory::setDisableMBeanRegistry);
163167
customizeStaticResources(factory);
164-
customizeErrorReportValve(this.serverProperties.getError(), factory);
168+
customizeErrorReportValve(this.webProperties.getError(), factory);
165169
factory.setUseApr(getUseApr(this.tomcatProperties.getUseApr()));
166170
}
167171

module/spring-boot-tomcat/src/test/java/org/springframework/boot/tomcat/autoconfigure/TomcatWebServerFactoryCustomizerTests.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.junit.jupiter.api.BeforeEach;
3535
import org.junit.jupiter.api.Test;
3636

37+
import org.springframework.boot.autoconfigure.web.WebProperties;
3738
import org.springframework.boot.context.properties.bind.Bindable;
3839
import org.springframework.boot.context.properties.bind.Binder;
3940
import org.springframework.boot.context.properties.source.ConfigurationPropertySources;
@@ -74,13 +75,15 @@ class TomcatWebServerFactoryCustomizerTests {
7475

7576
private final TomcatServerProperties tomcatProperties = new TomcatServerProperties();
7677

78+
private final WebProperties webProperties = new WebProperties();
79+
7780
private TomcatWebServerFactoryCustomizer customizer;
7881

7982
@BeforeEach
8083
void setup() {
8184
ConfigurationPropertySources.attach(this.environment);
8285
this.customizer = new TomcatWebServerFactoryCustomizer(this.environment, this.serverProperties,
83-
this.tomcatProperties);
86+
this.tomcatProperties, this.webProperties);
8487
}
8588

8689
@Test

0 commit comments

Comments
 (0)