anchor.diff:  
   
   
  -[[howto-configure-undertow]]
  -=== Configure Undertow
  -Generally you can follow the advice from
  -"`<<howto-discover-build-in-options-for-external-properties>>`" about
  -`@ConfigurationProperties` (`ServerProperties` and `ServerProperties.Undertow` are the
  -main ones here). However, you should also look at `WebServerFactoryCustomizer`.
  -Once you have access to the `UndertowServletWebServerFactory`, you can use an
  -`UndertowBuilderCustomizer` to modify Undertow's configuration to meet your needs.
  -Alternatively, if you need more control and customization, you can add your own
  -`UndertowServletWebServerFactory`.
  -
  -
  -
   [[howto-enable-multiple-listeners-in-undertow]]
   === Enable Multiple Listeners with Undertow
   Add an `UndertowBuilderCustomizer` to the `UndertowServletWebServerFactory` and
  
positive.code: with the underlying WebSocket container. When deployed to a standalone servlet container,
  this role is performed by a servlet container initializer, and the
  `ServerEndpointExporter` bean is not required.
  
  
  
  [[how-to-enable-http-response-compression]]
  === Enable HTTP Response Compression
  HTTP response compression is supported by Jetty, Tomcat, and Undertow. It can be enabled
  in `application.properties`, as follows:
  
  [source,properties,indent=0,subs="verbatim,quotes,attributes"]
  ----
  	server.compression.enabled=true
  ----
  
  By default, responses must be at least 2048 bytes in length for compression to be
  performed. You can configure this behavior by setting the
  `server.compression.min-response-size` property.
  
  By default, responses are compressed only if their content type is one of the
  following:
  
  * `text/html`
  * `text/xml`
  * `text/plain`
  * `text/css`
  
  You can configure this behavior by setting the `server.compression.mime-types` property.
  
  
  
  
negative.code: 
  
  
  [[howto-change-the-http-port]]
  === Change the HTTP Port
  In a standalone application, the main HTTP port defaults to `8080` but can be set with
  `server.port` (for example, in `application.properties` or as a System property). Thanks
  to relaxed binding of `Environment` values, you can also use `SERVER_PORT` (for example,
  as an OS environment variable).
  
  To switch off the HTTP endpoints completely but still create a `WebApplicationContext`,
  use `server.port=-1`. (Doing so is sometimes useful for testing.)
  
  For more details, see
  "`<<spring-boot-features.adoc#boot-features-customizing-embedded-containers>>`"
  in the '`Spring Boot features`' section, or the
  {sc-spring-boot-autoconfigure}/web/ServerProperties.{sc-ext}[`ServerProperties`] source
  code.
  
  
  
  [[howto-user-a-random-unassigned-http-port]]
  === Use a Random Unassigned HTTP Port
  To scan for a free port (using OS natives to prevent clashes) use `server.port=0`.
  
  
  
  [[howto-discover-the-http-port-at-runtime]]
  === Discover the HTTP Port at Runtime
  You can access the port the server is running on from log output or from the
  `ServletWebServerApplicationContext` through its `WebServer`. The best way to get that and
  be sure that it has been initialized is to add a `@Bean` of type
  `ApplicationListener<ServletWebServerInitializedEvent>` and pull the container
  out of the event when it is published.
  
  Tests that use `@SpringBootTest(webEnvironment=WebEnvironment.RANDOM_PORT)` can
  also inject the actual port into a field by using the `@LocalServerPort` annotation, as
  shown in the following example:
  
  [source,java,indent=0,subs="verbatim,quotes,attributes"]
  ----
  	@RunWith(SpringJUnit4ClassRunner.class)
  	@SpringBootTest(webEnvironment=WebEnvironment.RANDOM_PORT)
  	public class MyWebIntegrationTests {
  
  		@Autowired
  		ServletWebServerApplicationContext server;
  
  		@LocalServerPort
  		int port;
  
  		// ...
  
  	}
  ----
  
  [NOTE]
  ====
  `@LocalServerPort` is a meta-annotation for `@Value("${local.server.port}")`. Do not try
  to inject the port in a regular application. As we just saw, the value is set only after
  the container has been initialized. Contrary to a test, application code callbacks are
  processed early (before the value is actually available).
  ====
  
  
  
  [[how-to-enable-http-response-compression]]
  === Enable HTTP Response Compression
  HTTP response compression is supported by Jetty, Tomcat, and Undertow. It can be enabled
  in `application.properties`, as follows:
  
  [source,properties,indent=0,subs="verbatim,quotes,attributes"]
  ----
  	server.compression.enabled=true
  ----
  
  By default, responses must be at least 2048 bytes in length for compression to be
  performed. You can configure this behavior by setting the
  `server.compression.min-response-size` property.
  
  By default, responses are compressed only if their content type is one of the
  following:
  
  * `text/html`
  * `text/xml`
  * `text/plain`
  * `text/css`
  
  You can configure this behavior by setting the `server.compression.mime-types` property.
  
  
  
  [[howto-configure-ssl]]
  === Configure SSL
  SSL can be configured declaratively by setting the various `+server.ssl.*+` properties,
  typically in `application.properties` or `application.yml`. The following example shows
  setting SSL properties in `application.properties`:
  
  [source,properties,indent=0,subs="verbatim,quotes,attributes"]
  ----
  	server.port=8443
  	server.ssl.key-store=classpath:keystore.jks
  	server.ssl.key-store-password=secret
  	server.ssl.key-password=another-secret
  ----
  
  See {sc-spring-boot}/web/server/Ssl.{sc-ext}[`Ssl`] for details of all of the
  supported properties.
  
  Using configuration such as the preceding example means the application no longer supports
  a plain HTTP connector at port 8080. Spring Boot does not support the configuration of
  both an HTTP connector and an HTTPS connector through `application.properties`. If you
  want to have both, you need to configure one of them programmatically. We recommend using
  `application.properties` to configure HTTPS, as the HTTP connector is the easier of the
  two to configure programmatically. See the
  {github-code}/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors[`spring-boot-sample-tomcat-multi-connectors`]
  sample project for an example.
  
  
  
  [[howto-configure-http2]]
  === Configure HTTP/2
  You can enable HTTP/2 support in your Spring Boot application with the
  `+server.http2.enabled+` configuration property. This support depends on the chosen web
  server and the application environment, since that protocol is not supported
  out-of-the-box by JDK8.
  
  [NOTE]
  ====
  Spring Boot does not support `h2c`, the cleartext version of the HTTP/2 protocol. So you
  must <<howto-configure-ssl, configure SSL first>>.
  ====
  
  
  
  [[howto-configure-http2-undertow]]
  ==== HTTP/2 with Undertow
  As of Undertow 1.4.0+, HTTP/2 is supported without any additional requirement on JDK8.
  
  
  
  [[howto-configure-http2-jetty]]
  ==== HTTP/2 with Jetty
  As of Jetty 9.4.8, HTTP/2 is also supported with the
  https://www.conscrypt.org/[Conscrypt library].
  To enable that support, your application needs to have two additional dependencies:
  `org.eclipse.jetty:jetty-alpn-conscrypt-server` and `org.eclipse.jetty.http2:http2-server`.
  
  
  
  [[howto-configure-http2-tomcat]]
  ==== HTTP/2 with Tomcat
  Spring Boot ships by default with Tomcat 8.5.x. With that version, HTTP/2 is only
  supported if the `libtcnative` library and its dependencies are installed on the host
  operating system.
  
  The library folder must be made available, if not already, to the JVM library path. You
  can do so with a JVM argument such as
  `-Djava.library.path=/usr/local/opt/tomcat-native/lib`. More on this in the
  https://tomcat.apache.org/tomcat-8.5-doc/apr.html[official Tomcat documentation].
  
  Starting Tomcat 8.5.x without that native support logs the following error:
  
  [indent=0,subs="attributes"]
  ----
  	ERROR 8787 --- [           main] o.a.coyote.http11.Http11NioProtocol      : The upgrade handler [org.apache.coyote.http2.Http2Protocol] for [h2] only supports upgrade via ALPN but has been configured for the ["https-jsse-nio-8443"] connector that does not support ALPN.
  ----
  
  This error is not fatal, and the application still starts with HTTP/1.1 SSL support.
  
  Running your application with Tomcat 9.0.x and JDK9 does not require any native library to
  be installed. To use Tomcat 9, you can override the `tomcat.version` build property with
  the version of your choice.
  
  
  
  [[howto-configure-webserver]]
  === Configure the Web Server
  
  Generally, you should first consider using one of the many available configuration keys
  and customize your web server by adding new entries in your `application.properties` (or
  `application.yml`, or environment, etc. see
  "`<<howto-discover-build-in-options-for-external-properties>>`"). The `server.{asterisk}`
  namespace is quite useful here, and it includes namespaces like `server.tomcat.{asterisk}`,
  `server.jetty.{asterisk}` and others, for server-specific features.
  See the list of <<common-application-properties>>.
  
  The previous sections covered already many common use cases, such as compression, SSL
  or HTTP/2. However, if a configuration key doesn't exist for your use case, you should
  then look at
  {dc-spring-boot}/web/server/WebServerFactoryCustomizer.html[`WebServerFactoryCustomizer`].
  You can declare such a component and get access to the server factory relevant to your
  choice: you should select the variant for the chosen Server (Tomcat, Jetty, Reactor Netty,
  Undertow) and the chosen web stack (Servlet or Reactive).
  
  In the following example, we're using Tomcat in a Servlet-based web application:
  
  [source,java,indent=0,subs="verbatim,quotes,attributes"]
  ----
  	@Component
  	public class MyTomcatWebServerCustomizer
  			implements WebServerFactoryCustomizer<TomcatServletWebServerFactory> {
  
  		@Override
  		public void customize(TomcatServletWebServerFactory factory) {
  			// customize the factory here
  		}
  	}
  ----
  
  Spring Boot currently provides:
  
  * `TomcatServletWebServerFactory` and `TomcatReactiveWebServerFactory` for Tomcat
  * `JettyServletWebServerFactory` and `JettyReactiveWebServerFactory` for Jetty
  * `UndertowServletWebServerFactory` and `UndertowReactiveWebServerFactory` for Undertow
  * `NettyReactiveWebServerFactory` for Reactor Netty
  
  Once you've got access to a `WebServerFactory`, you can often add customizers to it to
  configure specific parts, like connectors, server resources, or the server itself - all
  using server-specific APIs.
  
  As a last resort, you can also declare your own `WebServerFactory` component, which will
  override the one provided by Spring Boot. In this case, you can't rely on configuration
  properties in the `server` namespace anymore.
  
  
  
  