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.*")
})

把這個加到主啟動類上就可以了。

 

完結。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM