inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

자바와 스프링 부트로 생애 최초 서버 만들기, 누구나 쉽게 개발부터 배포까지! [서버 개발 올인원 패키지]

강의 소개 영상

26강 코딩 후 컨파일 시 오류 문의드립니다 !

1058

kas0320

작성한 질문수 1

1

 Description:

The bean 'userRepository', defined in com.group.libraryapp.domain.user.UserRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration, could not be registered. A bean with that name has already been defined in class path resource [com/group/libraryapp/config/UserConfiguration.class] and overriding is disabled.

Action:

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

delete 부분까지 코딩 후에 테스트 진행하려고 , 컴파일 시에 위와 같은 오류가 발생하고 있습니다.
구글링으로 아래 action 부분도 해보았으나 다른 오류들이 발생하네요 ㅜㅜ

spring-boot spring JPA java jpa mysql aws

답변 1

0

최태현

안녕하세요! kas0320님!! 질문 올려주셔서 감사드립니다!! 🙏

보내주신 내용을 확인해본 결과, UserRepositorybean으로 동시에 2개 등록되려 한 것 같습니다!

 

어떤 말씀이냐면요!!

public interface UserRepository extends JpaRepository<User, Long> {

}

라는 코드는 UserRepository 를 빈으로 등록합니다!! (즉, UserRepository를 스프링 컨테이너에 넣으려고 합니다)

그리고 아마 어딘가에 다음과 같은 코드도 있을거에요!!!

@Configuration
public class UserConfiguration {
  @Bean
  public UserRepository userRepository() {
    return new UserRepository(); // 정확하진 않더라도 비슷한 코드가 있을겁니다!
  }
}

이 코드 역시 UserRepository 를 빈으로 등록하려 합니다!

 

바로 여기서, 문제가 발생합니다!!! 진작 UserRepository 가 빈으로 존재하는데 UserConfiguration 에 의해 또 하나의 UserRepository 가 등록되려 하는 것이죠!

그래서 에러가 이렇게 말하고 있습니다.

  • The bean 'userRepository', defined in com.group.libraryapp.domain.user.UserRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration, could not be registered. A bean with that name has already been defined in class path resource [com/group/libraryapp/config/UserConfiguration.class] and overriding is disabled.

  • (= 그 이름을 갖는 Bean은 진작 존재하고 있다)

이 문제를 해결하기 위해서는 UserConfiguration 을 제거해주시면 됩니다!

 

꼭 해결되셨으면 좋겠습니다! 😊

감사합니다!! 🙇

패키지 구분에 대해 궁금한게 있습니다

0

20

2

리액트 관련 질문이 있습니다.

0

64

2

스프링부트 버전

0

73

2

7강 강의를 들으려고 했는데 오류가 나서 서버가 안 켜지는거 같아요.

0

59

2

33강. UserLoanHistory의 관계성에 대한 질문

1

56

2

Java JDK 버전 문의의 건

0

132

2

ec2 에서 Linux버전이 달라져서 설치가 안되는것 같은데 자료 최신화좀 해주세요.

0

88

3

h2 console 접속했을 테이블 질문

1

65

1

ec2 서버에서 스프링 실행도 되고 인바운드 설정까지 했는데 index.html 안됨

0

75

2

15강. updateUser() 질문

0

55

2

깃허브 질

0

82

2

여기까지 다 끝냈다고 하셨는데

0

79

2

왜안될까요

0

70

2

MySQL 창이안ㄴ뜹니다

0

59

2

포스트맨

0

50

1

spring 개념적인 질문

0

71

2

인텔리제이 샘플코드 실행 안됨 오류

0

140

2

aws 배포할때 .env 파일에 저장한 환경변수에 관하여 여쭤볼게 있습니다

0

84

1

마이그레이션 오류입니다.

0

171

3

Whitelabel Error Page 오류가 났습니다.

0

163

2

안녕하십니까! 오류가 났습니다.. 도와주세요 ㅜㅜ

1

93

3

궁금한게 있습니다.

0

60

2

DTO 관련

0

70

2

궁금한게 있습니다!

0

68

2