From 692a8c47ccd13cf68618e69e404753c04e054cf3 Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Wed, 29 Apr 2020 18:42:50 +0200 Subject: [PATCH] Rename property for registering default Servlet As a follow-up for gh-21214, this commit renames the property to: `"server.servlet.register-default-servlet=false"` Closes gh-21214 --- .../autoconfigure/web/ServerProperties.java | 19 +++++---- .../ServletWebServerFactoryCustomizer.java | 3 +- ...ervletWebServerFactoryCustomizerTests.java | 4 +- .../web/servlet/server/DefaultServlet.java | 40 ------------------- 4 files changed, 15 insertions(+), 51 deletions(-) delete mode 100644 spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/DefaultServlet.java diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java index 2b9a6ce38d5..48aee2b6549 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java @@ -38,7 +38,6 @@ import org.springframework.boot.web.server.Compression; import org.springframework.boot.web.server.Http2; import org.springframework.boot.web.server.Shutdown; import org.springframework.boot.web.server.Ssl; -import org.springframework.boot.web.servlet.server.DefaultServlet; import org.springframework.boot.web.servlet.server.Encoding; import org.springframework.boot.web.servlet.server.Jsp; import org.springframework.boot.web.servlet.server.Session; @@ -227,8 +226,10 @@ public class ServerProperties { */ private String applicationDisplayName = "application"; - @NestedConfigurationProperty - private final DefaultServlet defaultServlet = new DefaultServlet(); + /** + * Whether to register the default Servlet with the container. + */ + private boolean registerDefaultServlet = true; @NestedConfigurationProperty private final Encoding encoding = new Encoding(); @@ -263,12 +264,16 @@ public class ServerProperties { this.applicationDisplayName = displayName; } - public Map getContextParameters() { - return this.contextParameters; + public boolean isRegisterDefaultServlet() { + return this.registerDefaultServlet; } - public DefaultServlet getDefaultServlet() { - return this.defaultServlet; + public void setRegisterDefaultServlet(boolean registerDefaultServlet) { + this.registerDefaultServlet = registerDefaultServlet; + } + + public Map getContextParameters() { + return this.contextParameters; } public Encoding getEncoding() { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/ServletWebServerFactoryCustomizer.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/ServletWebServerFactoryCustomizer.java index c273259a517..6ce83bcc7b9 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/ServletWebServerFactoryCustomizer.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/ServletWebServerFactoryCustomizer.java @@ -53,8 +53,7 @@ public class ServletWebServerFactoryCustomizer map.from(this.serverProperties::getAddress).to(factory::setAddress); map.from(this.serverProperties.getServlet()::getContextPath).to(factory::setContextPath); map.from(this.serverProperties.getServlet()::getApplicationDisplayName).to(factory::setDisplayName); - map.from(this.serverProperties.getServlet().getDefaultServlet()::isRegistered) - .to(factory::setRegisterDefaultServlet); + map.from(this.serverProperties.getServlet()::isRegisterDefaultServlet).to(factory::setRegisterDefaultServlet); map.from(this.serverProperties.getServlet()::getSession).to(factory::setSession); map.from(this.serverProperties::getSsl).to(factory::setSsl); map.from(this.serverProperties.getServlet()::getJsp).to(factory::setJsp); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/ServletWebServerFactoryCustomizerTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/ServletWebServerFactoryCustomizerTests.java index b8d19810a20..92360864c3c 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/ServletWebServerFactoryCustomizerTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/ServletWebServerFactoryCustomizerTests.java @@ -77,9 +77,9 @@ class ServletWebServerFactoryCustomizerTests { @Test void testCustomizeDefaultServlet() { ConfigurableServletWebServerFactory factory = mock(ConfigurableServletWebServerFactory.class); - this.properties.getServlet().getDefaultServlet().setRegistered(true); + this.properties.getServlet().setRegisterDefaultServlet(false); this.customizer.customize(factory); - verify(factory).setRegisterDefaultServlet(true); + verify(factory).setRegisterDefaultServlet(false); } @Test diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/DefaultServlet.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/DefaultServlet.java deleted file mode 100644 index 6c04231240a..00000000000 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/DefaultServlet.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2012-2020 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. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.web.servlet.server; - -/** - * Default Servlet properties. - * - * @author Brian Clozel - * @since 2.3.0 - */ -public class DefaultServlet { - - /** - * Whether to enable the registration of the default Servlet with the container. - */ - private boolean registered = true; - - public boolean isRegistered() { - return this.registered; - } - - public void setRegistered(boolean registered) { - this.registered = registered; - } - -}