728x90
반응형
스프링 공부를 하던 도중
Description:
The bean 'memberService', defined in class path resource [hello/hellospring/SpringConfig.class], could not be registered. A bean with that name has already been defined in file [C:\project\hello-spring\hello-spring\out\production\classes\hello\hellospring\service\MemberService.class] and overriding is disabled.
Action:
Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true
위와 같은 오류가 발생했다.
오류 메시지를 잘 읽어보니 Service를 스프링 빈으로 등록하는 과정에서 overriding이 발생했다는 뜻이다.
스프링 빈으로 등록하는 방법에는 어노테이션을 활용하여 자동으로 등록하는 방법과 자신이 직접 등록하는 방법이 있다.
나의 경우 아래와 같이 두 방식을 동시에 사용하여 충돌이 일어난 것이었다.
<어노테이션을 활용한 자동 등록>
@Service
public class MemberService {
.
.
.
}
<스프링 빈으로 직접 등록>
@Bean
public MemberService memberService(){
.
.
.
}
나의 경우 해결 방안은 간단했다.
서비스의 어노테이션(@Service)를 지워버리고 스프링 빈으로 직접 등록하는 방식을 선택하였다.
에러 메시지에서 제안한 해결 방식은 아래와 같이 overriding을 허용하는 방식이었다.
spring.main.allow-bean-definition-overriding=true
나는 굳이 overriding을 할 필요가 없었지만 overriding이 필요하다면 허용을 해주면 될 것 같다.
728x90
반응형
'공부 > Spring' 카테고리의 다른 글
[Spring][인프런 스프링 입문] Test 코드 작성 (0) | 2023.01.02 |
---|---|
[Spring][인프런 스프링 입문] JPA 기본 사용법 (2) | 2023.01.01 |
[Spring][인프런 스프링 입문] JdbcTemplate 사용법 (0) | 2022.12.31 |
[Spring][인프런 스프링 입문] 스프링 빈과 의존 관계 (0) | 2022.12.29 |
[Spring][인프런 스프링 입문] 웹 개발 기초 (0) | 2022.12.28 |
댓글