公司的框架出了问题,多个项目启动报错,花费了半天时间解决,多亏最近钻研springframework源码。
背景公司有一套分布式spring alibaba架构的系统,分为边缘服务,和服务池服务,服务治理一般,没有全局规划,半年前有外购一套分布式CRM系统,强行注册到一个服务中心,突然某个版本的多个边缘服务启动报错,导致测试停顿半天。
启动代码
@CanaryCloudApplication(applicationName = "b2b-consumer-edge", serverServletContextPath = "/consumer") //框架注解
@EnableSwagger2
@EnableFeignClients(basePackages = {
"com.vd.canary.**","com.kakarote.crm.api.**"})
public class ConsumerEdgeApplication {
public static void main(String[] args) {
CanaryApplication.run(ConsumerEdgeApplication.class, args);
}
}
这里分析一下公司封装的框架,高度概括的看法就是“唬人”,优秀的框架检验标准就是实用,开发人员友好,不隐藏细节。
公司框架希望高度封装,让普通开发只是写调用接口,先不说业务如此复杂,框架的做到高度封装恐怕只是外包行业,比较人员水平低,不灵活,长期针对某一种产品,对于快速多变的互联网行业,框架需要保持灵活多变。
报错信息
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.vmplugin.v7.Java7$1 (file:/D:/apache-maven-3.0.4/maven_repository/org/codehaus/groovy/groovy/2.5.9/groovy-2.5.9.jar) to constructor java.lang.invoke.MethodHandles$Lookup(java.lang.Class,int)
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.vmplugin.v7.Java7$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
_____ _________ ___ _____
/ __ \| ___ \ \/ | / __ \
| / \/| |_/ / . . |______| / \/
| | | /| |\/| |______| |
| \__/\| |\ \| | | | | \__/\
\____/\_| \_\_| |_/ \____/
[b2b-consumer-edge:172.16.26.41:8456] 2021-07-28 14:16:25.671 WARN 7996 [] [main] com.alibaba.cloud.nacos.client.NacosPropertySourceBuilder : Ignore the empty nacos configuration and get it based on dataId[b2b-consumer-edge-dev_bb.yaml] & group[DEFAULT_GROUP]
[b2b-consumer-edge:172.16.26.41:8456] 2021-07-28 14:16:25.672 INFO 7996 [] [main] org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration : Located property source: [BootstrapPropertySource {
name='bootstrapProperties-b2b-consumer-edge-dev_bb.yaml,DEFAULT_GROUP'}, BootstrapPropertySource {
name='bootstrapProperties-b2b-consumer-edge.yaml,DEFAULT_GROUP'}, BootstrapPropertySource {
name='bootstrapProperties-b2b-consumer-edge,DEFAULT_GROUP'}, BootstrapPropertySource {
name='bootstrapProperties-crm-c-core.yaml,DEFAULT_GROUP'}]
[b2b-consumer-edge:172.16.26.41:9010] 2021-07-28 14:16:25.700 INFO 7996 [] [main] com.vd.canary.b2b.edge.consumer.ConsumerEdgeApplication : The following profiles are active: dev_bb
[b2b-consumer-edge:172.16.26.41:9010] 2021-07-28 14:16:29.122 WARN 7996 [] [main] org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'fileBillFeignClient.FeignClientSpecification' defined in null: Cannot register bean definition [Generic bean: class [org.springframework.cloud.openfeign.FeignClientSpecification]; scope=; abstract=false; lazyInit=null; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] for bean 'fileBillFeignClient.FeignClientSpecification': There is already [Generic bean: class [org.springframework.cloud.openfeign.FeignClientSpecification]; scope=; abstract=false; lazyInit=null; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] bound.
[b2b-consumer-edge:172.16.26.41:9010] 2021-07-28 14:16:29.131 INFO 7996 [] [main] org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
[b2b-consumer-edge:172.16.26.41:9010] 2021-07-28 14:16:29.137 DEBUG 7996 [] [main] org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter : Application failed to start due to an exception
org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'fileBillFeignClient.FeignClientSpecification' defined in null: Cannot register bean definition [Generic bean: class [org.springframework.cloud.openfeign.FeignClientSpecification]; scope=; abstract=false; lazyInit=null; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] for bean 'fileBillFeignClient.FeignClientSpecification': There is already [Generic bean: class [org.springframework.cloud.openfeign.FeignClientSpecification]; scope=; abstract=false; lazyInit=null; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName

本文讲述了在公司一套分布式Spring Alibaba架构系统中,由于边缘服务启动报错导致的问题。作者通过深入分析Spring Framework源码,发现了框架封装过度和依赖问题。在尝试解决BeanDefinition重复定义的问题时,发现是由于引入的CRM系统导致的冲突。最终,通过调整Maven依赖解决了问题。文章强调了在面对启动错误时,理解Spring Boot启动过程和BeanDefinition的重要性。
最低0.47元/天 解锁文章
1393

被折叠的 条评论
为什么被折叠?



