> For the complete documentation index, see [llms.txt](https://jack80342.gitbook.io/spring-boot/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jack80342.gitbook.io/spring-boot/iv.-spring-boot-features/23.-springapplication/23.6.-web-environment.md).

# 23.6. Web环境

`SpringApplication`将尝试为你创建正确类型的`ApplicationContext`，默认情况下，根据你开发的是否为web应用决定使用`AnnotationConfigApplicationContext`或`AnnotationConfigServletWebServerApplicationContext`。

用于确定是否为web环境的算法相当简单（判断是否存在某些类），你可以使用`setWebEnvironment(boolean webEnvironment)`覆盖默认行为。

通过调用`setApplicationContextClass(…)`，你可以完全控制`ApplicationContext`的类型。

**注** 在Junit测试中使用`SpringApplication`，调用`setWebEnvironment(false)`是很有意义的。
