인프런 커뮤니티 질문&답변
영한님처럼 application.properties에 한줄 추가해도 CoreApplication 안되는 상황
작성
·
297
0
학습하는 분들께 도움이 되고, 더 좋은 답변을 드릴 수 있도록 질문전에 다음을 꼭 확인해주세요.
1. 강의 내용과 관련된 질문을 남겨주세요.
2. 인프런의 질문 게시판과 자주 하는 질문(링크)을 먼저 확인해주세요.
(자주 하는 질문 링크: https://bit.ly/3fX6ygx)
3. 질문 잘하기 메뉴얼(링크)을 먼저 읽어주세요.
(질문 잘하기 메뉴얼 링크: https://bit.ly/2UfeqCG)
질문 시에는 위 내용은 삭제하고 다음 내용을 남겨주세요.
=========================================
[질문 템플릿]
1. 강의 내용과 관련된 질문인가요? (예/아니오)
2. 인프런의 질문 게시판과 자주 하는 질문에 없는 내용인가요? (예/아니오)
3. 질문 잘하기 메뉴얼을 읽어보셨나요? (예/아니오)
[질문 내용]
영한님처럼
spring.main.allow-bean-definition-overriding=true를 추가하고 정상실행이 되길 바라는데 안돼서요.
여러 자주묻는 질문 및 검색을 통해
-parameters 추가 및 out폴더 삭제 후 실행
Gradle로 변경
심지어 Gradle 최신 버전으로 변경까지
다 해봤는데 안돼서 묻습니다.
아래는 에러화면입니다.
현재 스프링부트 버전이 3.3.3인데 그래서 그런걸까요?
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 1 of constructor in hello.core.order.OrderServiceImpl required a single bean, but 2 were found:
- rateDiscountPolicy: defined in file [C:\Users\sungwoo\OneDrive\study\core\build\classes\java\main\hello\core\discount\RateDiscountPolicy.class]
- discountPolicy: defined by method 'discountPolicy' in class path resource [hello/core/AppConfig.class]
This may be due to missing parameter name information
Action:
Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed
Ensure that your compiler is configured to use the '-parameters' flag.
You may need to update both your build tool settings as well as your IDE.
(See https://github.com/spring-projects/spring-framework/wiki/Upgrading-to-Spring-Framework-6.x#parameter-name-retention)
Execution failed for task ':CoreApplication.main()'.
> Process 'command 'C:\Program Files\JAVA\jdk-17\bin\java.exe'' finished with non-zero exit value 1
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.
Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
For more on this, please refer to https://docs.gradle.org/8.10.1/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.
BUILD FAILED in 2s
3 actionable tasks: 1 executed, 2 up-to-date
답변 2
0
안녕하세요, 인프런 AI 인턴입니다. 배성우님.
에러 메시지를 확인한 결과 Duplicate bean definition 문제로 보입니다. 이 문제는 한 타입에 대해 여러 개의 빈이 정의되어 있어, 스프링이 어떤 빈을 주입해야 할지 결정하지 못하면서 발생합니다. Spring 부트에서 NoUniqueBeanDefinitionException 오류는 주로 빈 정의가 중복된 경우 나타납니다.
이를 해결하기 위해서는 아래와 같은 몇 가지 방법을 사용하실 수 있습니다.
해결 방법:
- @Primary 어노테이션 사용:
여러 빈 중에서 하나를 기본 빈으로 설정하려면@Primary어노테이션을 사용하시면 됩니다.
@Primary
@Bean
public DiscountPolicy rateDiscountPolicy() {
return new RateDiscountPolicy();
}
- @Qualifier 어노테이션 사용:
주입할 특정 빈을 명시적으로 지정하려면@Qualifier어노테이션을 사용하시면 됩니다.
@Autowired
public OrderServiceImpl(MemberRepository memberRepository, @Qualifier("rateDiscountPolicy") DiscountPolicy discountPolicy) {
this.memberRepository = memberRepository;
this.discountPolicy = discountPolicy;
}
추가 참고 자료:
- CoreApplicationTests 오류 : 타입에 여러 빈이 존재할 때 어떤 빈을 주입해야 하는지 명확하지 않아 발생하는 문제에 대해 설명하고 있으며,
@Qualifier나@Primary어노테이션을 사용하는 방법 제시.
- Unresolved Spring Boot CoreApplication 문제 :
NoUniqueBeanDefinitionException문제 해결을 위한 다양한 해결 방법 설명.
이 외에도 스프링 컨텍스트 관련 오류에서 자주 언급되는 방법들도 있으니, 관련 답변을 참고하시기 바랍니다. 이와 관련된 자세한 내용은 github spring-framework의 가이드에서 확인해보실 수 있습니다.
저는 질문자님의 이해를 돕고자 지식공유자님의 기존 답변을 참고하여 유사한 답변 링크를 추천해드리고 있습니다.
현재 베타 기능으로 답변이 만족스럽지 않을 수 있는 점 양해 부탁드립니다. 🙏
추가적으로 궁금한 점이 있으시면, 이어서 질문해 주세요. 곧 지식공유자께서 답변해 주실 것입니다.






@Primary나
@Qualifier 어노테이션밖에 방법이 없는건가요?