inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

스프링 핵심 원리 - 기본편

@Configuration과 바이트코드 조작의 마법

예상과 같게 AppConfig class가 출력이 됩니다..??

273

깨위

작성한 질문수 18

0

안녕하세요..!

강의내용에 따르면 

class hello.core.AppConfig 이렇게 출력이 안나와야하는데,,

저는 예상과 같게

이렇게 출력이 됩니다..

뭐가 문제일까요..?????????

코드는 제가 친것을 지우고 강의자료 복사붙여넣기 한 결과입니다..

package hello.core.singleton;

import hello.core.AppConfig;
import hello.core.member.MemberRepository;
import hello.core.member.MemberServiceImpl;
import hello.core.order.OrderServiceImpl;
import org.junit.jupiter.api.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import static org.assertj.core.api.Assertions.*;
public class ConfigurationSingletonTest {
@Test
void configurationTest() {
ApplicationContext ac = new
AnnotationConfigApplicationContext(AppConfig.class);
MemberServiceImpl memberService = ac.getBean("memberService",
MemberServiceImpl.class);
OrderServiceImpl orderService = ac.getBean("orderService",
OrderServiceImpl.class);
MemberRepository memberRepository = ac.getBean("memberRepository",
MemberRepository.class);
//모두 같은 인스턴스를 참고하고 있다.
System.out.println("memberService -> memberRepository = " +
memberService.getMemberRepository());
System.out.println("orderService -> memberRepository = " +
orderService.getMemberRepository());
System.out.println("memberRepository = " + memberRepository);
//모두 같은 인스턴스를 참고하고 있다.
assertThat(memberService.getMemberRepository()).isSameAs(memberRepository);

assertThat(orderService.getMemberRepository()).isSameAs(memberRepository);

}

@Test
void configurationDeep() {
ApplicationContext ac = new
AnnotationConfigApplicationContext(AppConfig.class);
//AppConfig도 스프링 빈으로 등록된다.
AppConfig bean = ac.getBean(AppConfig.class);

System.out.println("bean = " + bean.getClass());
//출력: bean = class hello.core.AppConfig$$EnhancerBySpringCGLIB$$bd479d70
}
}

spring oop

답변 1

0

OMG

안녕하세요. 깨위님, 공식 서포터즈 OMG입니다.

AppConfig 클래스 상단에 @Configuration을 붙이고 안붙이고 각각 테스트 해주세요 :)


감사합니다.

fieldInjectionTest() 질문

0

58

1

AutoAppConfig의 존재이유

0

52

1

AppConfig와 스프링 빈 질문

0

57

1

[영한님]Spring Boot 및 프로젝트 생성

0

124

2

퀴즈가 안열려요

0

104

2

회원 도메인 인터페이스 개발

0

114

2

빈 스코프 개념의 중요성

0

95

1

SingletonService가 JVM이 뜰 때 생성되는게 맞나요?

0

152

2

섹션3. 11 회원객체 다이어그램

0

81

1

OCP, DIP과 @Qualifier 어노테이션에 대해서 질문합니다.

0

78

1

코드 자료

0

137

2

구현체가 동적으로 정해질 때, 팩토리 기법을 사용하나요?

0

134

2

MemberService의 인터페이스를 왜 사용하는지 궁금합니다.

0

148

1

롬복 @Setter를 써야 하는 상황이 있는건가요?

0

144

1

빈 등록 메서드의 파라미터가 빈이 아니어도 되나요?

0

139

1

테스트 속도가 나중에 영향이 있을까요?

0

128

1

gradle 설정 안떠서 질문 남깁니다!

0

266

2

build.gradle로 프로젝트를 여는 이유

0

162

1

provider 사용하는 이유

0

164

1

다음 강의 뭘 들어야 할까요

0

193

2

프로토타입 빈, 직접 destroy 호출 안 할 경우

0

114

1

beanB

0

135

2

퀴즈다시풀기

0

109

1

Gradle로 바꿔도 오류가 똑같이 발생하네요 ㅠㅠ

0

164

2