当包含时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则返回。truestarter-web
也许应该OnWebApplicationCondition尊重的设置spring.main.web-application-type?