某Spring Boot项目接入 apollo 后启动 dubbo 报错Caused by: java.lang.IllegalStateException: ApplicationConfig.application == null
.
根据异常猜测是 dubbo 启动时未读取到 apollo 内的配置。
解决方法
apollo-client 升到 1.2.0 之后,然后在application.properties
文件内添加配置apollo.bootstrap.eagerLoad.enabled=true
解决步骤复盘
0x01
先Google关键字 dubbo 2.6.2 apollo
, 第二条 “继承dubbo配置不生效…”.
0x02
点开第二条之后发现跟我们的问题毫无关系,但是里面提到 apollo use cases
.
0x03
使用 SourceTree 下载 apollo-use-cases,并在本机跑起来,发现没问题。
0x04
对比支付系统与其中的spring-boot-dubbo-consumer项目的异同。
- dubbo 版本一致
- dubbo-spring-boot-starter版本差 0.0.1
- 支付系统启动类上多@EnableJpaRepositories, @EnableCaching,@EnableSwagger2。
- 发现支付系统启动类里上还多一个@ImportResource(value = {“classpath*:commons-dubbo-api.xml”}.
0x05
在发现的异同里,跟 dubbo 关系最大的就是第四条。给spring-boot-dubbo-consumer的添加commons-dubbo-api-balcony
依赖,然后在启动类上添加注解 @ImportResource(value = {"classpath*:commons-dubbo-api.xml"}
问题复现。可以肯定这个问题是 apollo 与 dubbo 的兼容性问题。
0x06
访问 appollo issues, 以 dubbo
作为关键字搜索。结果差不多一页,⌘ + F
用浏览器的查找配置
.在第三个高亮项里找到跟我一模一样的问题。 1.2.0版本已经发布,支持把Apollo配置加载提到初始化日志系统之前,可以解决此issue中提到的问题。
,升级 apollo 到 1.2.0 问题依旧存在。
0x07
回顾该 issue, 之前提到 不过测试了一下,#1614 合并后就可以解决这个问题。
,进入#1614 发现配置apollo.bootstrap.eagerLoad.enabled
项,把 apollo.bootstrap.eagerLoad.enabled=true
放入项目application.properties,可成功启动项目。
相关截图
0x01
0x02
0x04
0x06
0x07
解决问题总耗时 30 分钟左右。
完整异常
1 | org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'alipayController': Unsatisfied dependency expressed through field 'payService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'payServiceImpl': Unsatisfied dependency expressed through field 'commandInvokeService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'commandInvokeServiceImpl': Unsatisfied dependency expressed through method 'setCommandMap' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'alipayBatchPayCommand': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'alipayServiceImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dubbo.balconyService': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: ApplicationConfig.application == null |