Polish Undertow contribution

Closes gh-1779
This commit is contained in:
Andy Wilkinson
2014-11-18 21:00:28 +00:00
parent c501b889af
commit 1864d79077
24 changed files with 608 additions and 268 deletions

View File

@@ -158,8 +158,8 @@ for our starter REST application:
Spring Boot makes `-D` arguments available as properties accessible from a Spring
`Environment` instance. The `server.port` configuration property is fed to the embedded
Tomcat or Jetty instance which then uses it when it starts up. The `$PORT` environment
variable is assigned to us by the Heroku PaaS.
Tomcat, Jetty or Undertow instance which then uses it when it starts up. The `$PORT`
environment variable is assigned to us by the Heroku PaaS.
Heroku by default will use Java 1.6. This is fine as long as your Maven or Gradle build
is set to use the same version (Maven users can use the `java.version` property). If you

View File

@@ -556,6 +556,61 @@ of ways. Or the nuclear option is to add your own `JettyEmbeddedServletContainer
[[howto-use-undertow-instead-of-tomcat]]
=== Use Undertow instead of Tomcat
Using Undertow instead of Tomcat is very similar to <<howto-use-jetty-instead-of-tomcat,
using Jetty instead of Tomcat>>. You need to exclude the Tomcat dependencies and include
the Undertow starter instead.
Example in Maven:
[source,xml,indent=0,subs="verbatim,quotes,attributes"]
----
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
----
Example in Gradle:
[source,groovy,indent=0,subs="verbatim,quotes,attributes"]
----
configurations {
compile.exclude module: "spring-boot-starter-tomcat"
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web:{spring-boot-version}")
compile("org.springframework.boot:spring-boot-starter-undertow:{spring-boot-version}")
// ...
}
----
[[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), but also look at
`EmbeddedServletContainerCustomizer`. Once you have access to the
`UndertowEmbeddedServletContainerFactory` you can use an `UndertowBuilderCustomizer` to
modify Undertow's configuration to meet your needs. Or the nuclear option is to add your
own `UndertowEmbeddedServletContainerFactory`.
[[howto-use-tomcat-8]]
=== Use Tomcat 8
Tomcat 8 works with Spring Boot, but the default is to use Tomcat 7 (so we can support

View File

@@ -810,8 +810,8 @@ possible.
[[boot-features-developing-web-applications]]
== Developing web applications
Spring Boot is well suited for web application development. You can easily create a
self-contained HTTP server using embedded Tomcat or Jetty. Most web applications will
use the `spring-boot-starter-web` module to get up and running quickly.
self-contained HTTP server using embedded Tomcat, Jetty, or Undertow. Most web
applications will use the `spring-boot-starter-web` module to get up and running quickly.
If you haven't yet developed a Spring Boot web application you can follow the
"Hello World!" example in the
@@ -1093,9 +1093,9 @@ asks for them to be scanned in its `Filter` registration).
[[boot-features-embedded-container]]
=== Embedded servlet container support
Spring Boot includes support for embedded Tomcat and Jetty servers. Most developers will
simply use the appropriate '`Starter POM`' to obtain a fully configured instance. By
default both Tomcat and Jetty will listen for HTTP requests on port `8080`.
Spring Boot includes support for embedded Tomcat, Jetty, and Undertow servers. Most
developers will simply use the appropriate '`Starter POM`' to obtain a fully configured
instance. By default the embedded server will listen for HTTP requests on port `8080`.
@@ -1121,8 +1121,9 @@ interface.
Under the hood Spring Boot uses a new type of `ApplicationContext` for embedded
servlet container support. The `EmbeddedWebApplicationContext` is a special
type of `WebApplicationContext` that bootstraps itself by searching for a single
`EmbeddedServletContainerFactory` bean. Usually a `TomcatEmbeddedServletContainerFactory`
or `JettyEmbeddedServletContainerFactory` will have been auto-configured.
`EmbeddedServletContainerFactory` bean. Usually a `TomcatEmbeddedServletContainerFactory`,
`JettyEmbeddedServletContainerFactory`, or `UndertowEmbeddedServletContainerFactory` will
have been auto-configured.
NOTE: You usually won't need to be aware of these implementation classes. Most
applications will be auto-configured and the appropriate `ApplicationContext` and
@@ -1176,8 +1177,8 @@ methods.
[[boot-features-customizing-configurableembeddedservletcontainerfactory-directly]]
===== Customizing ConfigurableEmbeddedServletContainer directly
If the above customization techniques are too limited, you can register the
`TomcatEmbeddedServletContainerFactory` or `JettyEmbeddedServletContainerFactory` bean
yourself.
`TomcatEmbeddedServletContainerFactory`, `JettyEmbeddedServletContainerFactory` or
`UndertowEmbeddedServletContainerFactory` bean yourself.
[source,java,indent=0]
----
@@ -1208,6 +1209,8 @@ packaged as an executable archive), there are some limitations in the JSP suppor
* Jetty does not currently work as an embedded container with JSPs.
* Undertow does not support JSPs
There is a {github-code}/spring-boot-samples/spring-boot-sample-web-jsp[JSP sample] so
you can see how to set things up.

View File

@@ -348,6 +348,9 @@ swap specific technical facets.
|`spring-boot-starter-tomcat`
|Import Spring Boot's default HTTP engine (Tomcat).
|`spring-boot-starter-undertow`
|Imports the Undertow HTTP engine (to be used as an alternative to Tomcat)
|===
TIP: For a list of additional community contributed starter POMs, see the