이너 static class
283
작성한 질문수 65
package hello.core.beanfind;
import hello.core.AppConfig;
import hello.core.repository.MemberRepository;
import hello.core.repository.MemoryMemberRepository;
import hello.core.service.MemberService;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.NoUniqueBeanDefinitionException;
import org.springframework.beans.factory.UnsatisfiedDependencyException;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import static org.junit.jupiter.api.Assertions.*;
public class ApplicationContextSameBeanFindTest {
AnnotationConfigApplicationContext ac=new AnnotationConfigApplicationContext(SameBeanConfig.class);
@Test
@DisplayName("타입으로 조회시 같은 타입이 둘 이상 있으면, 중복 오류가 발생한다")
void findBeanByTypeDuplicate() {
//DiscountPolicy bean = ac.getBean(MemberRepository.class);
assertThrows(NoUniqueBeanDefinitionException.class, () ->
ac.getBean(MemberRepository.class));
}
@Configuration
static class SameBeanConfig{
@Bean
public MemberRepository memberRepository(){
return new MemoryMemberRepository();
}
@Bean
public MemberRepository memberRepository2(){
return new MemoryMemberRepository();
}
}
이 코드에서 static이너클래스면 실행이 되고 그냥 이너클래스이면 안되는 이유가 뭔지
궁금합니다.
}
답변 1
1
안녕하세요. dduckmane 님, 공식 서포터즈 OMG입니다.
잘 정리된 답변 글 링크 첨부합니다.
참고해주세요 :)
https://www.inflearn.com/questions/257297
감사합니다.
회원 도메인 인터페이스 개발
0
49
1
빈 스코프 개념의 중요성
0
36
1
SingletonService가 JVM이 뜰 때 생성되는게 맞나요?
0
81
2
섹션3. 11 회원객체 다이어그램
0
42
1
OCP, DIP과 @Qualifier 어노테이션에 대해서 질문합니다.
0
44
1
코드 자료
0
95
2
구현체가 동적으로 정해질 때, 팩토리 기법을 사용하나요?
0
93
2
MemberService의 인터페이스를 왜 사용하는지 궁금합니다.
0
110
1
롬복 @Setter를 써야 하는 상황이 있는건가요?
0
112
1
빈 등록 메서드의 파라미터가 빈이 아니어도 되나요?
0
97
1
테스트 속도가 나중에 영향이 있을까요?
0
98
1
gradle 설정 안떠서 질문 남깁니다!
0
166
2
build.gradle로 프로젝트를 여는 이유
0
114
1
provider 사용하는 이유
0
115
1
다음 강의 뭘 들어야 할까요
0
147
2
프로토타입 빈, 직접 destroy 호출 안 할 경우
0
78
1
beanB
0
100
2
퀴즈다시풀기
0
83
1
Gradle로 바꿔도 오류가 똑같이 발생하네요 ㅠㅠ
0
116
2
"중복 등록과 충돌" 강의에서 강사님과 다른 에러가 발생합니다.
0
99
3
run 실행했는데 결과창이 이렇게 뜨네요 왜 그런건가요>
0
130
2
도메인의 정의?
0
72
1
ApplicationContext 질문입니다.
0
74
1
@Scope의 proxyMode를 사용할때 단위 테스트 방법
0
112
2





