spring-boot: spring.main.web-application-type from application.properties is not effective in @SpringBootTest
Given the way that @Conditional(NotReactiveWebApplicationCondition.class) is designed in RestTemplateAutoConfiguration,
if we have both spring-web and spring-webflux dependencies, the condition evaluates to false, and rest template is not autconfigured. This happened to me simply because I am importing prometheus-rsocket-spring which contains webflux as dependency
This did not happen in previous versions, I just updated to 2.6. I tried to disabled it by means of spring.main.web-application-type: servlet but it still does not configure it
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 15 (10 by maintainers)
Hey @nightswimmings, thanks for the report. I’ve edited the title of your issue and marked it as a bug.
Looks like #29169 isn’t fixed 😕 The reproducer is using the newest Spring Boot 2.6.6. I can reproduce it in 2.5.12, too.
Thanks for the reproducer. There’s indeed a bug.
This YAML content is ignored when running tests via
@SpringBootTest. It doesn’t matter if the YAML is insrc/main/resourcesorsrc/test/resources. That’s why themainmethod runs without problems, but the tests do not.org.springframework.boot.autoconfigure.condition.OnWebApplicationCondition#isReactiveWebApplicationreturnstruein tests if this is in the YAML, becausecontext.getResourceLoader()is aorg.springframework.boot.web.reactive.context.GenericReactiveWebApplicationContext.But when using
@SpringBootTest(properties = "spring.main.web-application-type=NONE"), thenorg.springframework.boot.autoconfigure.condition.OnWebApplicationCondition#isReactiveWebApplicationreturnsfalsein tests, ascontext.getResourceLoader()is aorg.springframework.context.annotation.AnnotationConfigApplicationContext. And then theRestTemplateBuilderbean is available.This could be related to https://github.com/spring-projects/spring-boot/issues/29170, but I’m not sure if it’s the same bug. @wilkinsona what do you think?
Sounds like there are some similarities with #29170 and #29695.