인프런 영문 브랜드 로고
인프런 영문 브랜드 로고

Inflearn Community Q&A

bepoz's profile image
bepoz

asked

Spring Core Principles - Basics

Prototype Scope - Issues when using with singleton beans

ApplicationContext에 대해서

Written on

·

362

16

안녕하세요 영한님 15:15 부분의 ApplicationContext에 대해 질문이 있습니다.

@Autowired를 통해 주입을 받으셨는데, ApplicationContext는 스프링에서 기본적으로 빈 등록을 해주는 객체이기 때문에 바로 주입받는 것이 가능한건가요?? 

springoop

Answer 1

29

yh님의 프로필 이미지
yh
Instructor

안녕하세요. kangsy763님

ApplicationContext는 스프링 빈을 관리하는 컨테이너 입니다. 컨테이너가 스프링 빈을 관리하기 때문에 컨테이너 차제가 스프링 빈으로 등록되는 것은 아닙니다.

@Autowired는 스프링 빈도 찾아주지만, 이렇게 ApplicationContext 같은 것도 편리하게 찾을 수 있는 부가 기능도 함께 제공합니다.

그래서 다음 코드는 실패하지만,

ApplicationContext bean = ac.getBean(ApplicationContext.class);

다음 코드는 성공합니다.

@Autowired ApplicationContext ac;

감사합니다.

감사합니다. 궁금증이 해결됐습니다.

bepoz's profile image
bepoz

asked

Ask a question