Only create a WebTestClient with WebFlux
This commit updates WebTestClientAutoConfiguration to only create a WebTestClient when running a WebFlux-based application as mocking the context only works with that mode at the moment. Closes gh-12318
This commit is contained in:
@@ -29,7 +29,8 @@ import org.springframework.boot.test.autoconfigure.properties.PropertyMapping;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
|
||||
/**
|
||||
* Annotation that can be applied to a test class to enable a {@link WebTestClient}.
|
||||
* Annotation that can be applied to a test class to enable a {@link WebTestClient}. At
|
||||
* the moment, only WebFlux applications are supported.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @since 2.0.0
|
||||
|
||||
@@ -22,9 +22,11 @@ import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.http.codec.CodecsAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.web.reactive.WebFluxAutoConfiguration;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.boot.web.codec.CodecCustomizer;
|
||||
@@ -33,6 +35,7 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
import org.springframework.web.server.WebHandler;
|
||||
|
||||
/**
|
||||
* Auto-configuration for {@link WebTestClient}.
|
||||
@@ -43,12 +46,13 @@ import org.springframework.web.reactive.function.client.WebClient;
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass({ WebClient.class, WebTestClient.class })
|
||||
@AutoConfigureAfter(CodecsAutoConfiguration.class)
|
||||
@AutoConfigureAfter({ CodecsAutoConfiguration.class, WebFluxAutoConfiguration.class })
|
||||
@EnableConfigurationProperties
|
||||
public class WebTestClientAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnBean(WebHandler.class)
|
||||
public WebTestClient webTestClient(ApplicationContext applicationContext,
|
||||
List<WebTestClientBuilderCustomizer> customizers) {
|
||||
WebTestClient.Builder builder = WebTestClient
|
||||
|
||||
Reference in New Issue
Block a user