Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure the WebClient to be present before enabling the WebTestClientContextCustomizer #24152

Closed
wants to merge 1 commit into from

Conversation

gesellix
Copy link
Contributor

@gesellix gesellix commented Nov 13, 2020

Our @SpringBootTest in a SERVLET SpringApplication fails with the stacktrace below after an upgrade from Spring-Boot 2.3.6 to 2.4.0.

It seems like a check on the presence of WebClient had been removed with the refactoring at 6b437ec#diff-0468685a60929025a2cf3fe3ed6a01021f7b6865d562536897e5915c3a483c40L42.

This pull request adds the check for isWebClientPresent().

stacktrace
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
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
	at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:176)
	at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:101)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1879)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getObjectForBeanInstance(AbstractAutowireCapableBeanFactory.java:1268)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:267)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
	at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1161)
	at org.spockframework.spring.SpringMockTestExecutionListener.beforeTestMethod(SpringMockTestExecutionListener.java:79)
	at org.spockframework.spring.AbstractSpringTestExecutionListener.beforeTestMethod(AbstractSpringTestExecutionListener.java:39)
	at org.springframework.test.context.TestContextManager.beforeTestMethod(TestContextManager.java:289)
	at org.spockframework.spring.SpringTestContextManager.beforeTestMethod(SpringTestContextManager.java:60)
	at org.spockframework.spring.SpringInterceptor.interceptSetupMethod(SpringInterceptor.java:50)
	at org.spockframework.runtime.extension.AbstractMethodInterceptor.intercept(AbstractMethodInterceptor.java:30)
	at org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:97)
	at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass(JUnitTestClassExecutor.java:110)
	at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:58)
	at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:38)
	at org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass(AbstractJUnitTestClassProcessor.java:62)
	at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
	at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:119)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:182)
	at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:164)
	at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:414)
	at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
	at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
	at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
	at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: java.lang.IllegalStateException: No suitable default ClientHttpConnector found
	at org.springframework.test.web.reactive.server.DefaultWebTestClientBuilder.initConnector(DefaultWebTestClientBuilder.java:295)
	at org.springframework.test.web.reactive.server.DefaultWebTestClientBuilder.build(DefaultWebTestClientBuilder.java:266)
	at org.springframework.boot.test.web.reactive.server.WebTestClientContextCustomizer$WebTestClientFactory.createWebTestClient(WebTestClientContextCustomizer.java:162)
	at org.springframework.boot.test.web.reactive.server.WebTestClientContextCustomizer$WebTestClientFactory.getObject(WebTestClientContextCustomizer.java:150)
	at org.springframework.boot.test.web.reactive.server.WebTestClientContextCustomizer$WebTestClientFactory.getObject(WebTestClientContextCustomizer.java:126)
	at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:169)
	... 34 more

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 13, 2020
@wilkinsona wilkinsona added this to the 2.4.1 milestone Nov 13, 2020
@wilkinsona wilkinsona added type: regression A regression from a previous release and removed status: waiting-for-triage An issue we've not yet triaged labels Nov 13, 2020
@gesellix
Copy link
Contributor Author

Please leave a note if you'd like to have a test case for the change.

@wilkinsona
Copy link
Member

Thanks very much for the pull request, @gesellix. A test for this would be great if you have the time. It should be possible to test it using @ClassPathExclusions to exclude the spring-webflux jar from the classpath and then verify that the factory does not produce a customizer.

@gesellix
Copy link
Contributor Author

@wilkinsona thanks for the hints about @ClassPathExclusions, I've implemented both test cases in separate test classes. In other news: I found the checkstyle checks and especially the format task very helpful!

@@ -0,0 +1,55 @@
/*
* Copyright 2012-2019 the original author or authors.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, if there's a policy about changing the copyright notice to ...-2020, but I guess that could be adjusted for the whole code base :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We change the date whenever the file is updated. This should be 2020 but don't worry we'll take care of that when merging.

@snicoll snicoll self-assigned this Nov 25, 2020
snicoll pushed a commit that referenced this pull request Nov 25, 2020
This commit reinstanties the isWeBClientPresent() check so that
WebTestClientContextCustomizer is only added if a web client is
available.

See gh-24152
snicoll added a commit that referenced this pull request Nov 25, 2020
@snicoll snicoll closed this in 39953bb Nov 25, 2020
@snicoll
Copy link
Member

snicoll commented Nov 25, 2020

@gesellix thank you for the report and the PR.

@gesellix
Copy link
Contributor Author

You're welcome, thanks for merging! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: regression A regression from a previous release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants