Update reference guide to stop mentioning setWebEnvironment
Closes gh-12330
This commit is contained in:
@@ -155,14 +155,15 @@ in the '`Spring Boot features`' section for more information.
|
||||
Not all Spring applications have to be web applications (or web services). If you want to
|
||||
execute some code in a `main` method but also bootstrap a Spring application to set up
|
||||
the infrastructure to use, you can use the `SpringApplication` features of Spring
|
||||
Boot. A `SpringApplication` changes its `ApplicationContext` class, depending on whether it
|
||||
thinks it needs a web application or not. The first thing you can do to help it is to
|
||||
leave the servlet API dependencies off the classpath. If you cannot do that (for example, you
|
||||
run two applications from the same code base) then you can explicitly call
|
||||
`setWebEnvironment(false)` on your `SpringApplication` instance or set the
|
||||
`applicationContextClass` property (through the Java API or with external properties).
|
||||
Application code that you want to run as your business logic can be implemented as a
|
||||
`CommandLineRunner` and dropped into the context as a `@Bean` definition.
|
||||
Boot. A `SpringApplication` changes its `ApplicationContext` class, depending on whether
|
||||
it thinks it needs a web application or not. The first thing you can do to help it is to
|
||||
leave server-related dependencies (e.g. servlet API) off the classpath. If you cannot do
|
||||
that (for example, you run two applications from the same code base) then you can
|
||||
explicitly call `setWebApplicationType(WebApplicationType.NONE)` on your
|
||||
`SpringApplication` instance or set the `applicationContextClass` property (through the
|
||||
Java API or with external properties). Application code that you want to run as your
|
||||
business logic can be implemented as a `CommandLineRunner` and dropped into the context as
|
||||
a `@Bean` definition.
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -261,19 +261,23 @@ by implementing `ApplicationContextAware` or, if the listener is a bean, by usin
|
||||
[[boot-features-web-environment]]
|
||||
=== Web Environment
|
||||
A `SpringApplication` attempts to create the right type of `ApplicationContext` on your
|
||||
behalf. By default, an `AnnotationConfigApplicationContext` or
|
||||
`AnnotationConfigServletWebServerApplicationContext` is used, depending on whether you
|
||||
are developing a web application or not.
|
||||
behalf. The algorithm used to determine a `WebEnvironmentType` is fairly simple:
|
||||
|
||||
The algorithm used to determine a "`web environment`" is fairly simplistic (it is based
|
||||
on the presence of a few classes). If you need to override the default, you can use
|
||||
`setWebEnvironment(boolean webEnvironment)`.
|
||||
* If Spring MVC is present, an `AnnotationConfigServletWebServerApplicationContext` is
|
||||
used
|
||||
* If Spring MVC is not present and Spring WebFlux is present, an
|
||||
`AnnotationConfigReactiveWebApplicationContext` is used
|
||||
* Otherwise, `AnnotationConfigApplicationContext` is used
|
||||
|
||||
This means that if you are using Spring MVC and the new `WebClient` from Spring WebFlux in
|
||||
the same application, Spring MVC will be used by default. You can override that easily
|
||||
by calling `setWebApplicationType(WebApplicationType)`.
|
||||
|
||||
It is also possible to take complete control of the `ApplicationContext` type that is
|
||||
used by calling `setApplicationContextClass(...)`.
|
||||
|
||||
TIP: It is often desirable to call `setWebEnvironment(false)` when using
|
||||
`SpringApplication` within a JUnit test.
|
||||
TIP: It is often desirable to call `setWebApplicationType(WebApplicationType.NONE)` when
|
||||
using `SpringApplication` within a JUnit test.
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user