Skip to content

spring-boot-test 2.4.0 WebTestClient creation exception #24305

@lyoumi

Description

@lyoumi

Since spring-boot-test 2.4.0 update I got org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.test.web.reactive.server.WebTestClient': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: No suitable default ClientHttpConnector found but when I check maven dependencies no reactive dependencies was found. After investigation I found discrepancy between spring-boot-test:2.3.5.RELEASE and spring-boot-test:2.4.0 in WebTestClientContextCustomizerFactory:

2.3.5.RELEASE (and earlier):

    public ContextCustomizer createContextCustomizer(Class<?> testClass, List<ContextConfigurationAttributes> configAttributes) {
        return this.isWebClientPresent() && AnnotatedElementUtils.findMergedAnnotation(testClass, SpringBootTest.class) != null ? new WebTestClientContextCustomizer() : null;
    }

    private boolean isWebClientPresent() {
        return ClassUtils.isPresent("org.springframework.web.reactive.function.client.WebClient", this.getClass().getClassLoader());
    }

2.4.0:

	public ContextCustomizer createContextCustomizer(Class<?> testClass, List<ContextConfigurationAttributes> configAttributes) {
		SpringBootTest springBootTest = TestContextAnnotationUtils.findMergedAnnotation(testClass, SpringBootTest.class);
		return (springBootTest != null) ? new WebTestClientContextCustomizer() : null;
	}

	private boolean isWebClientPresent() {
		return ClassUtils.isPresent("org.springframework.web.reactive.function.client.WebClient", getClass().getClassLoader());
	}

If I'm correct there is no notes about this update at 2.4.0 release notes page. Could you check it and reply how to resolve this case?
Expected behaviour: no exceptions during test run because no WebClient present in classpath.
Actual behaviour: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.test.web.reactive.server.WebTestClient': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: No suitable default ClientHttpConnector found

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions