Add property for registering default Servlet
This commit adds a new configuration property for configuring the registration of the default Servlet in Servlet containers. `"server.servlet.default-servlet.registered=false"` The default of this property is still `true`, as it's been the case in previous releases. Closes gh-21214
This commit is contained in:
parent
767156167b
commit
c7c01f8ab4
|
@ -38,6 +38,7 @@ import org.springframework.boot.web.server.Compression;
|
||||||
import org.springframework.boot.web.server.Http2;
|
import org.springframework.boot.web.server.Http2;
|
||||||
import org.springframework.boot.web.server.Shutdown;
|
import org.springframework.boot.web.server.Shutdown;
|
||||||
import org.springframework.boot.web.server.Ssl;
|
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.Encoding;
|
||||||
import org.springframework.boot.web.servlet.server.Jsp;
|
import org.springframework.boot.web.servlet.server.Jsp;
|
||||||
import org.springframework.boot.web.servlet.server.Session;
|
import org.springframework.boot.web.servlet.server.Session;
|
||||||
|
@ -226,6 +227,9 @@ public class ServerProperties {
|
||||||
*/
|
*/
|
||||||
private String applicationDisplayName = "application";
|
private String applicationDisplayName = "application";
|
||||||
|
|
||||||
|
@NestedConfigurationProperty
|
||||||
|
private final DefaultServlet defaultServlet = new DefaultServlet();
|
||||||
|
|
||||||
@NestedConfigurationProperty
|
@NestedConfigurationProperty
|
||||||
private final Encoding encoding = new Encoding();
|
private final Encoding encoding = new Encoding();
|
||||||
|
|
||||||
|
@ -263,6 +267,10 @@ public class ServerProperties {
|
||||||
return this.contextParameters;
|
return this.contextParameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DefaultServlet getDefaultServlet() {
|
||||||
|
return this.defaultServlet;
|
||||||
|
}
|
||||||
|
|
||||||
public Encoding getEncoding() {
|
public Encoding getEncoding() {
|
||||||
return this.encoding;
|
return this.encoding;
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,6 +53,8 @@ public class ServletWebServerFactoryCustomizer
|
||||||
map.from(this.serverProperties::getAddress).to(factory::setAddress);
|
map.from(this.serverProperties::getAddress).to(factory::setAddress);
|
||||||
map.from(this.serverProperties.getServlet()::getContextPath).to(factory::setContextPath);
|
map.from(this.serverProperties.getServlet()::getContextPath).to(factory::setContextPath);
|
||||||
map.from(this.serverProperties.getServlet()::getApplicationDisplayName).to(factory::setDisplayName);
|
map.from(this.serverProperties.getServlet()::getApplicationDisplayName).to(factory::setDisplayName);
|
||||||
|
map.from(this.serverProperties.getServlet().getDefaultServlet()::isRegistered)
|
||||||
|
.to(factory::setRegisterDefaultServlet);
|
||||||
map.from(this.serverProperties.getServlet()::getSession).to(factory::setSession);
|
map.from(this.serverProperties.getServlet()::getSession).to(factory::setSession);
|
||||||
map.from(this.serverProperties::getSsl).to(factory::setSsl);
|
map.from(this.serverProperties::getSsl).to(factory::setSsl);
|
||||||
map.from(this.serverProperties.getServlet()::getJsp).to(factory::setJsp);
|
map.from(this.serverProperties.getServlet()::getJsp).to(factory::setJsp);
|
||||||
|
|
|
@ -74,6 +74,14 @@ class ServletWebServerFactoryCustomizerTests {
|
||||||
verify(factory).setDisplayName("TestName");
|
verify(factory).setDisplayName("TestName");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testCustomizeDefaultServlet() {
|
||||||
|
ConfigurableServletWebServerFactory factory = mock(ConfigurableServletWebServerFactory.class);
|
||||||
|
this.properties.getServlet().getDefaultServlet().setRegistered(true);
|
||||||
|
this.customizer.customize(factory);
|
||||||
|
verify(factory).setRegisterDefaultServlet(true);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testCustomizeSsl() {
|
void testCustomizeSsl() {
|
||||||
ConfigurableServletWebServerFactory factory = mock(ConfigurableServletWebServerFactory.class);
|
ConfigurableServletWebServerFactory factory = mock(ConfigurableServletWebServerFactory.class);
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue