23.6 Web Environment(web环境)
1 | A SpringApplication attempts to create the right type of |
SpringApplication试图根据您的行为创建正确的ApplicationContext类型,用于确定WebEnvironmentType的算法非常简单:1
2
3• 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
- 如果使用的是Spring MVC的框架,AnnotationConfigServletWebServerApplicationContext将会被使用
- 如果使用的不是Spring MVC框架,使用的是WebFlux框架,AnnotationConfigReactiveWebApplicationContext上下文将会被使用
- 其他情况,AnnotationConfigApplicationContext将会被使用
1
2
3
4This 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).
这意味着,如果您在同一个应用中使用了Spring MVC也使用了Spring WebFlux的Web客户端,Spring MVC将会作为默认框架。您可以通过setWebApplicationType(WebApplicationType).来重写这个默认。1
2It is also possible to take complete control of the ApplicationContext
type that is used by calling setApplicationContextClass(… ).
也可以通过调用setApplicationContextClass(… )来设置上下文的类型。1
2It is often desirable to call setWebApplicationType(WebApplicationType.NONE)
when using SpringApplication within a JUnit test.
当使用JUnit测试的时候也可以使用setWebApplicationType(WebApplicationType.NONE)来设置上下文类型。