Skip to content

Commit ce2a682

Browse files
committed
Add ServletContext initialization documentation
Update the documentation to include a section about ServletContext initialization with embedded servlet containers. This update is to primarily highlight that `WebApplicationInitializers` and Servlet 3.0+ `ServletContainerInitializers` are not called. Fixes gh-4643
1 parent acb3fb5 commit ce2a682

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,8 +1310,23 @@ map to `+/*+`.
13101310

13111311
If convention-based mapping is not flexible enough you can use the
13121312
`ServletRegistrationBean`, `FilterRegistrationBean` and `ServletListenerRegistrationBean`
1313-
classes for complete control. You can also register items directly if your bean implements
1314-
the `ServletContextInitializer` interface.
1313+
classes for complete control.
1314+
1315+
1316+
1317+
[[boot-features-embedded-container-context-initializer]]
1318+
==== Servlet Context Initialization
1319+
Embedded servlet containers will not directly execute the Servlet 3.0+
1320+
`javax.servlet.ServletContainerInitializer` interface, or Spring's
1321+
`org.springframework.web.WebApplicationInitializer` interface. This is an intentional
1322+
design decision intended to reduce the risk that 3rd party libraries designed to run
1323+
inside a war will break Spring Boot applications.
1324+
1325+
If you need to perform servlet context initialization in a Spring Boot application, you
1326+
should register a bean that implements the
1327+
`org.springframework.boot.context.embedded.ServletContextInitializer` interface. The
1328+
single `onStartup` method provides access to the `ServletContext`, and can easily be used
1329+
as an adapter to an existing `WebApplicationInitializer if necessary.
13151330

13161331

13171332

0 commit comments

Comments
 (0)