Closed
Description
Affects versions: 2.6.2
If you create Spring Boot application with spring-boot-starter-web
and spring-boot-starter-webflux
depdencencies, but in test/resources/application.properties
declare:
spring.main.web-application-type=reactive
and create test:
@SpringBootTest
class ReactiveOrServletApplicationTests {
@Autowired(required = false)
private org.springframework.boot.web.servlet.error.ErrorAttributes errorAttributesServlet;
@Autowired(required = false)
private org.springframework.boot.web.reactive.error.ErrorAttributes errorAttributesReactive;
@Test
void contextLoads() {
assertThat(errorAttributesServlet).isNull();
assertThat(errorAttributesReactive).isNotNull();
}
}
assertions will fail - Spring will create Servlet beans and ignore Reactive beans. Please see report:
ErrorWebFluxAutoConfiguration:
Did not match:
- not a reactive web application (OnWebApplicationCondition)
Matched:
- @ConditionalOnClass found required class 'org.springframework.web.reactive.config.WebFluxConfigurer' (OnClassCondition)
ErrorMvcAutoConfiguration matched:
- @ConditionalOnClass found required classes 'javax.servlet.Servlet', 'org.springframework.web.servlet.DispatcherServlet' (OnClassCondition)
- found 'session' scope (OnWebApplicationCondition)
That's somehow similar to #29169 Here a reason is evaluation:
GenericWebApplicationContext
is used as ConfigurableApplicationContext