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.
-
컴포넌트 스캔과 자동 의존관계 설정
@Controller가 있으면 자동 등록된다.좀 더 자세히, DI (Dependency Injection) 의존성 주입
스프링 빈을 등록하는 2가지 방법
컴포넌트 스캔 원리
@Component가 있으면 스프링 빈으로 자동 등록된다.@Controller컨트롤러가 스프링 빈으로 자동 등록된 이유도 컴포넌트 스캔 때문이다.@Component를 포함하는 다음 애노테이션도 스프링 빈으로 자동 등록된다.@Controller@Service@Repository회원 서비스 스프링 빈 등록
memberService와memberRepository를 둘 다 스프링 컨테이너에 스프링 빈으로 등록하고, 스프링 빈에 등록되어 있는 맴버 리포지토리를memberService에 넣어준다.자바 코드로 직접 스프링 빈 등록하기
memberService와memberRepository의@Service@Repository@Autowired애노테이션을 제거하고 진행한다.@Configuration을 읽고,@Bean을 보고 스프링 빈에 등록하라는 의미로 받아들인다.@Controller는 스프링이 관리하는 것이기에@Controller라고 쓰면 컴포넌트 스캔에 올라가게되고@Autowired로 연결한다.참고
Beta Was this translation helpful? Give feedback.
All reactions