一次springboot扫描范围引起的启动报错

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

公司的框架出了问题,多个项目启动报错,花费了半天时间解决,多亏最近钻研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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值