헤르메스 LIFE

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

Exception

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

헤르메스의날개 2022. 2. 20. 23:19
728x90

1. STS 버전 : 4.13.1

2. JDK 버전 : OpenJDK 11.0.14_9_x64

3. Tomcat 버전 : 9.0.56

4. Maven 버전 : 3.8.4

5. Spring 버전 : Spring Boot 2.6.3

6. Database : Docker 에 DB 설치

- primary - PostgreSQL 13.3
- secondary - MySQL DB 8.0.28


오류내용

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

Description:

The bean 'productRepository', defined in com.study.springboot.product.repository.ProductRepository defined in @EnableJpaRepositories declared on SecondaryDatasourceConfiguration, could not be registered. A bean with that name has already been defined in com.study.springboot.product.repository.ProductRepository defined in @EnableJpaRepositories declared on PrimaryDatasourceConfig and overriding is disabled.

Action:

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

해결

SpringBoot 2.1 부터 overriding 옵션이 false 되었다고 합니다.

Bean Overriding을 활성화 하기 위해 아래 옵션을 추가 하면 해결된다고 합니다.

spring:
  main:
    allow-bean-definition-overriding: true

spring:
  main:
    allow-bean-definition-overriding: true
  h2:
    console:
      enabled: true
      path: /h2-console
      
  jpa:
    generate-ddl: true
    hibernate:
      ddl-auto: create
    show-sql: false
    properties:
      hibernatte:
        format_sql: true
  profiles:
    active: local

참고

https://www.baeldung.com/spring-boot-bean-definition-override-exception

https://n1tjrgns.tistory.com/172

 

spring.main.allow-bean-definition-overriding: true 에러 해결

스프링 배치를 실행하던 중 createQueryProvider라는 bean을 생성하는 과정에서 에러가 발생했다. 에러내용은 아래와 같다. Description: ​ The bean 'createQueryProvider', defined in class path resource [co..

n1tjrgns.tistory.com

 

728x90