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)

Most upvoted comments

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.

spring:
  main:
    web-application-type: none

This YAML content is ignored when running tests via @SpringBootTest. It doesn’t matter if the YAML is in src/main/resources or src/test/resources. That’s why the main method runs without problems, but the tests do not.

org.springframework.boot.autoconfigure.condition.OnWebApplicationCondition#isReactiveWebApplication returns true in tests if this is in the YAML, because context.getResourceLoader() is a org.springframework.boot.web.reactive.context.GenericReactiveWebApplicationContext.

But when using @SpringBootTest(properties = "spring.main.web-application-type=NONE"), then org.springframework.boot.autoconfigure.condition.OnWebApplicationCondition#isReactiveWebApplication returns false in tests, as context.getResourceLoader() is a org.springframework.context.annotation.AnnotationConfigApplicationContext. And then the RestTemplateBuilder bean 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.