스프링 ApplicationContext

Woolly·2023년 5월 8일
0
MemberService memberService = applicationContext.getBean("memberService", MemberService.class);
OrderService orderService = applicationContext.getBean("orderService", OrderService.class);

getBean 함수를 호출할 때, name과 xxxService.class를 인자로 넘김
-> 여기서 .class가 의미하는 것은?

바로 클래스 타입

객체 인스턴스는 new 문법으로 '초기화'하여 클래스 내 멤버들에 접근할 수 있다.

하지만 .class 를 쓰면 클래스 타입으로 접근하여 클래스 속성과 각 멤버에 대한 여러 정보에 접근할 수 있다.

이것을 '리플렉션' 이라고 함.

'리플렉션'이란?

  • 구체적인 클래스 타입을 알지 못하더라도 그 클래스의 메서드, 타입, 변수들에 접근할 수 있도록 해주는 자바 API

추가 참고 : https://jeongkyun-it.tistory.com/225

profile
Ad Astra

0개의 댓글