You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
섹션4. 스프링 빈과 의존관계
1. 컴포넌트 스캔과 자동 의존관계 설정
스프링 빈이란?
Spring IOC가 관리하는 자바 객체를 빈(Bean)이라고 부른다.
스프링 컨테이너를 통해 객체를 생성하면 인스턴스를 하나만 생성한 후 공용으로 사용할 수 있다.
스프링은 기본적을 스프링 빈을 싱글톤으로 등록하기 때문이다. 특별한 경우를 제외하고는 대부분 싱글톤을 사용한다.
컴포넌트 스캔 원리
@component 애노테이션이 있으면 스프링 빈으로 자동 등록된다.
@controller, @service, @repository 모두 @component 를 포함한다.
2. 자바 코드로 직접 스프링 빈 등록하기
정형화 되지 않거나 상황에 따라 구현 클래스를 변경해야 하는 경우 직접 스프링 빈을 등록하는 방법을 많이 사용한다.
향후 MemoryMemberRepository 를 다른 Repository 로 변경할 예정인 우리 수업과 같은 경우에는 자바 코드로 스프링 빈을 설정하는 방식이 편리하다.
Beta Was this translation helpful? Give feedback.
All reactions