You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Apache Camel 3.20.3升级至4.4.2引发循环依赖问题

Spring Boot与Apache Camel升级后JUnit测试出现循环依赖异常

我们正在对Java、Camel和Spring Boot进行版本升级,具体版本变更如下:

  • Java:11 → 17
  • Spring Boot:2.5.2 → 3.2.6
  • Apache Camel:3.20.3 → 4.4.2

仅升级JDK到17时,JUnit测试用例运行正常;但同时升级Spring Boot和Apache Camel后,运行测试用例出现异常。尚未尝试部署到服务器,已执行过mvn clean install操作。

异常堆栈信息

java.lang.IllegalStateException: Failed to load ApplicationContext for [WebMergedContextConfiguration@5a564a61 testClass = NorthDataRoutesTest, locations = ["classpath:/camel-context.xml"], classes = [], contextInitializerClasses = [], activeProfiles = ["dev"], propertySourceDescriptors = [], propertySourceProperties = ["org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true"], contextCustomizers = [[ImportsContextCustomizer@3aee72d8 key = [@org.apache.camel.test.spring.junit5.CamelSpringBootTest(), @org.springframework.boot.test.context.SpringBootTest(args={}, classes={}, properties={}, useMainMethod=NEVER, value={}, webEnvironment=MOCK), @org.springframework.context.annotation.Import(value={org.springframework.boot.autoconfigure.AutoConfigurationPackages.Registrar.class}), @org.springframework.context.annotation.ComponentScan(basePackageClasses={}, basePackages={"testConfiguration"}, excludeFilters={}, includeFilters={}, lazyInit=false, nameGenerator=org.springframework.beans.factory.support.BeanNameGenerator.class, resourcePattern="**/*.class", scopeResolver=org.springframework.context.annotation.AnnotationScopeMetadataResolver.class, scopedProxy=DEFAULT, useDefaultFilters=true, value={"testConfiguration"}), @org.springframework.test.context.TestExecutionListeners(inheritListeners=true, listeners={org.apache.camel.test.spring.junit5.CamelSpringTestContextLoaderTestExecutionListener.class, org.apache.camel.test.spring.junit5.CamelSpringBootExecutionListener.class, org.apache.camel.test.spring.junit5.StopWatchTestExecutionListener.class}, mergeMode=MERGE_WITH_DEFAULTS, value={org.apache.camel.test.spring.junit5.CamelSpringTestContextLoaderTestExecutionListener.class, org.apache.camel.test.spring.junit5.CamelSpringBootExecutionListener.class, org.apache.camel.test.spring.junit5.StopWatchTestExecutionListener.class}), @org.apiguardian.api.API(consumers={"*"}, since="5.0", status=STABLE), @org.springframework.boot.autoconfigure.EnableAutoConfiguration(exclude={}, excludeName={}), @org.springframework.context.annotation.Import(value={org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.class}), @org.springframework.test.context.ContextConfiguration(classes={}, inheritInitializers=true, inheritLocations=true, initializers={}, loader=org.springframework.test.context.ContextLoader.class, locations={"classpath:/camel-context.xml"}, name="", value={"classpath:/camel-context.xml"}), @org.springframework.test.context.ActiveProfiles(inheritProfiles=true, profiles={"dev"}, resolver=org.springframework.test.context.ActiveProfilesResolver.class, value={"dev"}), @org.springframework.boot.autoconfigure.AutoConfigurationPackage(basePackageClasses={}, basePackages={}), @org.springframework.test.context.BootstrapWith(value=org.springframework.boot.test.context.SpringBootTestContextBootstrapper.class)]], org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@418c5a9c, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@332729ad, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@7b8b43c7, org.springframework.boot.test.autoconfigure.actuate.observability.ObservabilityContextCustomizerFactory$DisableObservabilityContextCustomizer@1f, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizer@3f67593e, org.springframework.boot.test.context.SpringBootTestAnnotation@c791c0a8], resourceBasePath = "src/main/webapp", contextLoader = org.springframework.boot.test.context.SpringBootContextLoader, parent = null]

    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:180)
    at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:130)
    at org.apache.camel.test.spring.junit5.CamelSpringBootExecutionListener.prepareTestInstance(CamelSpringBootExecutionListener.java:61)
    at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:247)
    at org.springframework.test.context.junit.jupiter.SpringExtension.postProcessTestInstance(SpringExtension.java:163)
    at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
    at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)
    at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625)
    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
    at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
    at java.base/java.util.stream.StreamSpliterators$WrappingSpliterator.forEachRemaining(StreamSpliterators.java:310)
    at java.base/java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:735)
    at java.base/java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:734)
    at java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:762)
    at java.base/java.util.Optional.orElseGet(Optional.java:364)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'template': Error creating bean with name 'camel-1': Error creating bean with name 'org.apache.camel.impl.health.DefaultHealthCheckRegistry': Error creating bean with name 'camel-1': Requested bean is currently in creation: Is there an unresolvable circular reference?
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:608)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:523)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:325)

已尝试的解决方案

  • 创建同版本的示例项目,测试用例运行正常。
  • 添加Camel文档中相关健康检查配置并设置为false。
  • 创建自定义类继承DefaultHealthCheckRegistry并启用懒加载。
  • 在自动配置注解中排除DefaultHealthCheckRegistry类。

内容的提问来源于stack exchange,提问作者Rakeshkumaran

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 15:12:02