@@ -487,8 +487,78 @@ Spring Boot. The definitive list comes from searching the source code for
487
487
488
488
489
489
490
- [[howto-embedded-servlet-containers]]
491
- == Embedded servlet containers
490
+ [[howto-embedded-web-servers]]
491
+ == Embedded Web servers
492
+
493
+
494
+
495
+ [[howto-use-another-web-server]]
496
+ === Use another Web server
497
+ The Spring Boot starters bring a default embedded container for you:
498
+
499
+ * `spring-boot-starter-web` brings Tomcat with `spring-boot-starter-tomcat`,
500
+ but `spring-boot-starter-jetty` and `spring-boot-starter-undertow` can be used instead.
501
+ * `spring-boot-starter-webflux` brings Reactor Netty with `spring-boot-starter-reactor-netty`,
502
+ but `spring-boot-starter-tomcat`, `spring-boot-starter-jetty` and
503
+ `spring-boot-starter-undertow` can be used instead.
504
+
505
+ NOTE: Many starters only support Spring MVC, so they transitively bring
506
+ `spring-boot-starter-web` into your application classpath
507
+
508
+ If you choose to use a different HTTP server, you need to exclude those dependencies
509
+ and include the one you chose instead. Spring Boot provides separate starters for
510
+ HTTP servers to help make this process as easy as possible.
511
+
512
+ Example in Maven, for Spring MVC:
513
+
514
+ [source,xml,indent=0,subs="verbatim,quotes,attributes"]
515
+ ----
516
+ <dependency>
517
+ <groupId>org.springframework.boot</groupId>
518
+ <artifactId>spring-boot-starter-web</artifactId>
519
+ <exclusions>
520
+ <!-- Exclude the Tomcat dependency -->
521
+ <exclusion>
522
+ <groupId>org.springframework.boot</groupId>
523
+ <artifactId>spring-boot-starter-tomcat</artifactId>
524
+ </exclusion>
525
+ </exclusions>
526
+ </dependency>
527
+ <!-- Use Jetty instead -->
528
+ <dependency>
529
+ <groupId>org.springframework.boot</groupId>
530
+ <artifactId>spring-boot-starter-jetty</artifactId>
531
+ </dependency>
532
+ ----
533
+
534
+ Example in Gradle, for Spring WebFlux:
535
+
536
+ [source,groovy,indent=0,subs="verbatim,quotes,attributes"]
537
+ ----
538
+ configurations {
539
+ // exclude Reactor Netty
540
+ compile.exclude module: 'spring-boot-starter-reactor-netty'
541
+ }
542
+
543
+ dependencies {
544
+ compile 'org.springframework.boot:spring-boot-starter-webflux'
545
+ // Use Undertow instead
546
+ compile 'org.springframework.boot:spring-boot-starter-undertow'
547
+ // ...
548
+ }
549
+ ----
550
+
551
+ NOTE: `spring-boot-starter-reactor-netty` is required to use the `WebClient`,
552
+ so excluding it is not required if you wish to use a different HTTP server.
553
+
554
+ [[howto-configure-jetty]]
555
+ === Configure Jetty
556
+ Generally you can follow the advice from
557
+ _<<howto-discover-build-in-options-for-external-properties>>_ about
558
+ `@ConfigurationProperties` (`ServerProperties` is the main one here), but also look at
559
+ `ServletWebServerFactoryCustomizer`. The Jetty APIs are quite rich so once you have
560
+ access to the `JettyServletWebServerFactory` you can modify it in a number
561
+ of ways. Or the nuclear option is to add your own `JettyServletWebServerFactory`.
492
562
493
563
494
564
@@ -828,104 +898,6 @@ include::{code-examples}/context/embedded/TomcatLegacyCookieProcessorExample.jav
828
898
829
899
830
900
831
- [[howto-use-jetty-instead-of-tomcat]]
832
- === Use Jetty instead of Tomcat
833
- The Spring Boot starters (`spring-boot-starter-web` in particular) use Tomcat as an
834
- embedded container by default. You need to exclude those dependencies and include the
835
- Jetty one instead. Spring Boot provides Tomcat and Jetty dependencies bundled together
836
- as separate starters to help make this process as easy as possible.
837
-
838
- Example in Maven:
839
-
840
- [source,xml,indent=0,subs="verbatim,quotes,attributes"]
841
- ----
842
- <dependency>
843
- <groupId>org.springframework.boot</groupId>
844
- <artifactId>spring-boot-starter-web</artifactId>
845
- <exclusions>
846
- <exclusion>
847
- <groupId>org.springframework.boot</groupId>
848
- <artifactId>spring-boot-starter-tomcat</artifactId>
849
- </exclusion>
850
- </exclusions>
851
- </dependency>
852
- <dependency>
853
- <groupId>org.springframework.boot</groupId>
854
- <artifactId>spring-boot-starter-jetty</artifactId>
855
- </dependency>
856
- ----
857
-
858
- Example in Gradle:
859
-
860
- [source,groovy,indent=0,subs="verbatim,quotes,attributes"]
861
- ----
862
- configurations {
863
- compile.exclude module: 'spring-boot-starter-tomcat'
864
- }
865
-
866
- dependencies {
867
- compile 'org.springframework.boot:spring-boot-starter-web'
868
- compile 'org.springframework.boot:spring-boot-starter-jetty'
869
- // ...
870
- }
871
- ----
872
-
873
-
874
-
875
- [[howto-configure-jetty]]
876
- === Configure Jetty
877
- Generally you can follow the advice from
878
- _<<howto-discover-build-in-options-for-external-properties>>_ about
879
- `@ConfigurationProperties` (`ServerProperties` is the main one here), but also look at
880
- `ServletWebServerFactoryCustomizer`. The Jetty APIs are quite rich so once you have
881
- access to the `JettyServletWebServerFactory` you can modify it in a number
882
- of ways. Or the nuclear option is to add your own `JettyServletWebServerFactory`.
883
-
884
-
885
-
886
- [[howto-use-undertow-instead-of-tomcat]]
887
- === Use Undertow instead of Tomcat
888
- Using Undertow instead of Tomcat is very similar to <<howto-use-jetty-instead-of-tomcat,
889
- using Jetty instead of Tomcat>>. You need to exclude the Tomcat dependencies and include
890
- the Undertow starter instead.
891
-
892
- Example in Maven:
893
-
894
- [source,xml,indent=0,subs="verbatim,quotes,attributes"]
895
- ----
896
- <dependency>
897
- <groupId>org.springframework.boot</groupId>
898
- <artifactId>spring-boot-starter-web</artifactId>
899
- <exclusions>
900
- <exclusion>
901
- <groupId>org.springframework.boot</groupId>
902
- <artifactId>spring-boot-starter-tomcat</artifactId>
903
- </exclusion>
904
- </exclusions>
905
- </dependency>
906
- <dependency>
907
- <groupId>org.springframework.boot</groupId>
908
- <artifactId>spring-boot-starter-undertow</artifactId>
909
- </dependency>
910
- ----
911
-
912
- Example in Gradle:
913
-
914
- [source,groovy,indent=0,subs="verbatim,quotes,attributes"]
915
- ----
916
- configurations {
917
- compile.exclude module: 'spring-boot-starter-tomcat'
918
- }
919
-
920
- dependencies {
921
- compile 'org.springframework.boot:spring-boot-starter-web'
922
- compile 'org.springframework.boot:spring-boot-starter-undertow'
923
- // ...
924
- }
925
- ----
926
-
927
-
928
-
929
901
[[howto-configure-undertow]]
930
902
=== Configure Undertow
931
903
Generally you can follow the advice from
@@ -1288,7 +1260,7 @@ Check out {sc-spring-boot-autoconfigure}/web/servlet/WebMvcAutoConfiguration.{sc
1288
1260
1289
1261
[[howto-http-clients-proxy-configuration]]
1290
1262
=== Configure RestTemplate to use a proxy
1291
- As described in <<spring-boot-features.adoc#boot-features-restclient -customization>>,
1263
+ As described in <<spring-boot-features.adoc#boot-features-resttemplate -customization>>,
1292
1264
a `RestTemplateCustomizer` can be used with `RestTemplateBuilder` to build a customized
1293
1265
`RestTemplate`. This is the recommended approach for creating a `RestTemplate` configured
1294
1266
to use a proxy.
0 commit comments