spring_reference/IV. Spring Boot features/22.5. Web environment.md

8 lines
644 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

### 22.5. Web环境
一个SpringApplication将尝试为你创建正确类型的ApplicationContext。在默认情况下使用AnnotationConfigApplicationContext或AnnotationConfigEmbeddedWebApplicationContext取决于你正在开发的是否是web应用。
用于确定一个web环境的算法相当简单基于是否存在某些类。如果需要覆盖默认行为你可以使用setWebEnvironment(boolean webEnvironment)。通过调用setApplicationContextClass(…)你可以完全控制ApplicationContext的类型。
**注**当JUnit测试里使用SpringApplication时调用setWebEnvironment(false)是可取的。