23.6 Web environment
A SpringApplication
will attempt to create the right type of ApplicationContext
on your behalf. By default, an AnnotationConfigApplicationContext
or AnnotationConfigEmbeddedWebApplicationContext
will be used, depending on whether you are developing a web application or not.
The algorithm used to determine a ‘web environment’ is fairly simplistic (based on the presence of a few classes). You can use setWebEnvironment(boolean webEnvironment)
if you need to override the default.
It is also possible to take complete control of the ApplicationContext
type that will be used by calling setApplicationContextClass(…)
.
Tip | |
---|---|
It is often desirable to call setWebEnvironment(false) when using SpringApplication within a JUnit test. |