-
Notifications
You must be signed in to change notification settings - Fork 41.7k
Closed
Description
When using an application that is using spring-boot-starter-webclient and NOT spring-boot-starter-webflux
@ConditionalOnWebApplication is evaluating to true when it should be false duirng @SpringBootTest runs.
It does not appear to be the case on normal application runs.
Steps to Reproduce
- Go to https://start.spring.io/
- Select Spring Boot 4.0.0 and add
Reactive HTTP Clientdependencies only. - Generate the project.
- Add the following test code:
package com.example.conditional_on_web_demo;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Configuration;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertAll;
@SpringBootTest
class ConditionalOnWebDemoApplicationTests {
@Configuration
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
static class MyServletConfiguration {
}
@Configuration
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE)
static class MyReactiveConfiguration {
}
@Configuration
@ConditionalOnWebApplication
static class MyGenericWebConfiguration {
}
@Test
void contextLoads(
@Autowired(required = false) MyServletConfiguration myServletConfiguration,
@Autowired(required = false) MyReactiveConfiguration myReactiveConfiguration,
@Autowired(required = false) MyGenericWebConfiguration myGenericWebConfiguration
) {
assertAll(
() -> assertThat(myServletConfiguration).isNull(),
() -> assertThat(myReactiveConfiguration).isNull(),
() -> assertThat(myGenericWebConfiguration).isNull()
);
}
}- Run the Test and observe the assertion errors (servlet will pass, reactive and generic will fail)
Metadata
Metadata
Assignees
Labels
type: bugA general bugA general bug