当包含时spring-boot-starter-web
,它RestTemplateBuilder
可以作为 bean 使用,并且自动配置报告如下所示:
RestTemplateAutoConfiguration matched:
- @ConditionalOnClass found required class 'org.springframework.web.client.RestTemplate' (OnClassCondition)
- NoneNestedConditions 0 matched 1 did not; NestedCondition on RestTemplateAutoConfiguration.NotReactiveWebApplicationCondition.ReactiveWebApplication not a reactive web application (RestTemplateAutoConfiguration.NotReactiveWebApplicationCondition)
当不包括时spring-boot-starter-web
,则RestTemplateBuilder
不能作为 bean 使用,并且自动配置报告如下所示:
RestTemplateAutoConfiguration:
Did not match:
- NoneNestedConditions 1 matched 0 did not; NestedCondition on RestTemplateAutoConfiguration.NotReactiveWebApplicationCondition.ReactiveWebApplication found ConfigurableReactiveWebEnvironment (RestTemplateAutoConfiguration.NotReactiveWebApplicationCondition)
Matched:
- @ConditionalOnClass found required class 'org.springframework.web.client.RestTemplate' (OnClassCondition)
RestTemplate
在两种情况下都在类路径上,因为spring-boot-starter-webflux
(由 拉入prometheus-rsocket-spring
)对 有依赖性org.springframework:spring-web
。
当starter-web
在类路径上时,org.springframework.boot.autoconfigure.condition.OnWebApplicationCondition#isReactiveWebApplication
返回,如果不在类路径上,match = false
则返回。true
starter-web
也许应该OnWebApplicationCondition
尊重的设置spring.main.web-application-type
?