• SpringBoot项目启动报错解决记录


    2020-06-29 11:14:37,181 - [WARN] o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'xxTmpRepository' defined in null: Cannot register bean definition [Root bean: class [org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] for bean 'xxTmpRepository': There is already [Root bean: class [org.springframework.data.jdbc.repository.support.JdbcRepositoryFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] bound.
    2020-06-29 11:14:37,196 - [ERROR] o.s.b.d.LoggingFailureAnalysisReporter -

    ***************************
    APPLICATION FAILED TO START
    ***************************

    Description:

    The bean 'xxTmpRepository', defined in null, could not be registered. A bean with that name has already been defined in null and overriding is disabled.

    Action:

    Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true

    上面是启动报错的日志输出,总之就是说有一个类声明已经存在了,你又没说可以覆盖,所以我就报错咯。

    解决方案有两个:

    1. 像上面说的那个,给配置文件添加一个 spring.main.allow-bean-definition-overriding=true 就可以了。

    2. 找到为啥会重复,然后把重复的去掉。

    上面的日志输出已经说了是 BeanDefinitionOverrideException 抛出来的 JpaRepositoryFactoryBean 与 JdbcRepositoryFactoryBean 冲突,也就是说这两个 BeanFactory 都尝试把 xxTmpRepository 进行处理,后面处理的那个就报错了。

    不让后面那处理就可以了,我这里这个 xxTmpRepository 是 JPA的 repository,按理说 jdbcRepository 不应该去管这个,谁知道咋回事儿呢?反正就是 jdbc越权了,需要限制一下下。

    安排!把 xxTmpRepository  所在的目录不让 jdbcRepository 扫描到。

    @EnableJdbcRepositories(excludeFilters = {
            @ComponentScan.Filter(
                    type = FilterType.ASPECTJ,
                    pattern = "com.xx.xxx.repotory.*")
    })

    把这个加到主启动类上就可以了。

    完结。

  • 相关阅读:
    KCF目标跟踪方法分析与总结
    C# 事件
    委托学习(3)
    委托学习(2)
    委托学习(1)
    本地无sqlserver服务下操作数据库 之GSQL
    unity Android 打包后读取 xml 文件
    Unity 3D 调用摄像头捕获照片 录像
    Unity 进度条3D制作(3D版)
    Unity 3D 进度条制作
  • 原文地址:https://www.cnblogs.com/kischn/p/13207028.html
Copyright © 2020-2023  润新知