스프링 컨테이너는 모두 BeanFactory라는 인터페이스를 구현하고 있다.
BeanFactory의 구현 클래스 중에 DefaultListableBeanFactory이 존재한다.
DefaultListableBeanFactory는 거의 대부분의 스프링 컨테이너는 이 클래스를 이용해 빈의 등록하고 관리하고 있다.
스프링에서는 DefaultListableBeanFactory 오브젝트를 @Autowired로 주입받아서 이용하게 해준다.
이 객체에서 getBeanDefinitionNames() 메소드가 있어 등록된 모든 빈 이름을 가져올 수 있다.
빈 이름을 이용해서 실제 빈과 빈 클래스 정보 등도 조회할 수 있다.
@ExtendWith(SpringExtension.class)
public class BeanTest {
@Autowired
DefaultListableBeanFactory bf;
@Test
public void beans(){
for(String n : bf.getBeanDefinitionNames()){
System.out.println(n + " \t" + bf.getBean(n).getClass().getName());
}
}
}
참고자료: 토비의 스프링 3.1 p.692
'백엔드 > Spring' 카테고리의 다른 글
[ 스프링 / Spring ] 4.x Controller Dto파라미터 매핑 안되는 현상 처리 (0) | 2021.07.15 |
---|---|
[ Spring / 스프링 ] 프로퍼티(.properties) 읽는 방법 (0) | 2021.06.15 |
[ Spring / 스프링 ] Annotation(어노테이션) 공부 - 4 [ Validation ] (0) | 2021.06.10 |
[ Spring / 스프링 ] Annotation(어노테이션) 공부 - 3 [ junit ] (0) | 2021.06.10 |
[ Spring / 스프링 ] Annotation(어노테이션) 공부 - 2 [ AOP ] (0) | 2021.06.10 |