`Spring Context is not yet refreshed` exceptions are thrown when adding Spring Sleuth dependency to project
See original GitHub issueI have a working project and I don’t change anything in it except for adding a gradle dependency on Spring Sleuth as below: implementation “org.springframework.cloud:spring-cloud-starter-sleuth:2.2.4.RELEASE”
When dependency is added I have occasional but frequent failures while running integration tests. Below is the example of the error being thrown:
Caused by:
java.lang.AssertionError: Spring Context [org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@738ef0bd, started on Thu Aug 13 13:40:44 CEST 2020, parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@57fbecf6] is not yet refreshed. This is unexpected. Reactor Context is [Context0{}] and name is [lambda]
at org.springframework.cloud.sleuth.instrument.reactor.ReactorSleuth.lambda$scopePassingSpanOperator$0(ReactorSleuth.java:94)
at reactor.core.publisher.FluxLift.subscribeOrReturn(FluxLift.java:50)
at reactor.core.publisher.Flux.subscribe(Flux.java:8311)
at reactor.core.publisher.Flux.subscribeWith(Flux.java:8494)
at reactor.core.publisher.Flux.subscribe(Flux.java:8295)
at reactor.core.publisher.Flux.subscribe(Flux.java:8222)
at reactor.core.publisher.Flux.subscribe(Flux.java:8140)
at com.klarna.card.transaction.listener.logging.TestLoggingHelper.testCorrelationIdLogInjection(TestLoggingHelper.java:100)
It looks like it is something related to Reactor project as well. I use WebFlux and SpringBoot 2.3.2.RELEASE version. Please, let me know if there is any other information that can be useful for investigation.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:6
- Comments:9 (3 by maintainers)
Top Results From Across the Web
Spring Boot 2.4.4 failed to start after upgrading - Stack Overflow
Please notice the difference between your dependency: spring-cloud-starter-zipkin:2.1.3.RELEASE and the ones you should use: spring-cloud-sleuth ...
Read more >Spring Cloud Sleuth Features
This section dives into the details of Spring Cloud Sleuth. Here you can learn about the key features that you may want to...
Read more >spring-cloud/spring-cloud-sleuth - Gitter
When I add Sleuth to one of my projects I get the following exception while running tests. Without Sleuth dependency it runs just...
Read more >The BeanDefinitionOverrideException in Spring Boot - Baeldung
5. Identifying the Beans in Conflict ... Notice that the exception reveals two important pieces of information. ... As a result, we can...
Read more >Easy Distributed Tracing with Spring Cloud Sleuth
There is no single log file, with a request spread across multiple server instances. How do you use logs in this situation? How...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I am having this same issue. When run independently, unit tests that use reactor APIs work fine, but when as part of a full mvn build, the unit tests that run after spring tests fail with this error.
It seems that spring-cloud-sleuth does not clean up its hooks when the spring context shuts down.
Adding this to my unit tests works around the problem:
We can see that some tests in spring-cloud-sleuth itself do the same thing (though it’s not clear if this is to work around the same problem, or because the tests actually expect the hooks to be dirtied by something inside the test itself): https://github.com/spring-cloud/spring-cloud-sleuth/blob/6e306e/tests/common/src/main/java/org/springframework/cloud/sleuth/instrument/web/client/HttpClientBeanPostProcessorTest.java#L51
It’s also possible to work around this by making each test class execute in its own JVM, although this may slow your build down considerably. E.g.:
Nope, no date at this point. If you really need to use it asap, you can use snapshots or https://jitpack.io/ and align your version to a concrete commit.