package org.example;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class ProjectConfig {
@Bean
public Parrot parrot1() {
Parrot p = new Parrot();
p.setName("Koko");
return p;
}
@Bean
public Parrot parrot2() {
Parrot p = new Parrot();
p.setName("Miki");
return p;
}
@Bean
public Person person(Parrot parrot2) {
Person p = new Person();
p.setName("Ella");
p.setParrot(parrot2);
return p;
}
}
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class ProjectConfig {
@Bean
public Parrot parrot1() {
Parrot p = new Parrot();
p.setName("Koko");
return p;
}
@Bean
public Parrot parrot2() {
Parrot p = new Parrot();
p.setName("Miki");
return p;
}
@Bean
public Person person(Parrot parrot2) {
Person p = new Person();
p.setName("Ella");
p.setParrot(parrot2);
return p;
}
}
이거 제미나이한테 물어보니까 Qualifier 쓰라는데 안쓰고는 못함?
니 오류를 갖고오셈; 안써도 자동매칭으로 파라메터 잘주입받을것같은데
parameter 0: No qualifying bean of type 'org.example.Parrot' available: expected single matching bean but found 2: parrot1,parrot2 Exception in thread "main" org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'person' defined in org.example.ProjectConfig: Unsatisfied dependency expressed through method 'person' parameter 0: No qualifying bean of type 'o
인텔리제이 씀
@글쓴 백갤러(117.17) 신기하네; 버전차이인가? 원래 안헷갈리고 잘잡아주는데 메서드 직접호출해 아니면 지피티쓰든가
해당 댓글은 삭제되었습니다.
그거 다운받아서 실행해도 똑같은 오류나
100페이지
person 패러미터 parrot이 지금 2개가 잡혀서 예외 터진건데 Parrot 어떤거 쓸지 @primary나 @qualifier로 집어주거나 아님 Parrot자체를 Parrot1 아님 Parrot2로 잡으셈
그래들쓰나요? 메이븐 쓰시나요?
컴파일 파라미터에 -parameters 추가해보세요
최신 버전 스프링에선 컴파일할때 파라미터 이름 뭉게버리고 바이트코드 만들어서 파라미터 이름으로 인식을 못한다네. 윗놈말마따라 컴파일 파라미터에 저거 추가해줘야 파라미터명 보존되는듯