doriver 2024. 2. 21. 19:27

섹션 4. 스프링컨테이너와 스프링 빈

( 커밋박은 코드 기준으로 복습함 )

1. 실행에서 로그출력 안됐던 문제 

src / main / resources 에 xml 파일 하나 만들어서 특정 코드 입력
<configuration>
  <appender class="ch.qos.logback.core.ConsoleAppender">
    <encoder> ~
      ~ 

이런식으로 하니 해결됨

이게 아마 프로젝트의 classpath?가 resources 쪽에 연결되있어서, 자동으로 해당 경로 읽는듯?

2. 컨테이너에 등록된 모든 빈 조회

AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext(AppConfig.class);

 

getBeanDefinitionNames() 로 스프링 컨테이너에 등록된 모든 빈 이름 얻을수 있고
빈 이름으로 빈 객체들을 확인을 해보면

( Object 로 조회한거랑 다르네, Object로 조회하면 추가로 ApplicationContext의 상위 인터페이스까지 나옴 )

여기엔 내가 설정정보로 넣은 스프링 빈들 뿐만 아니라

org.springframework.  context.annotation.ConfigurationClassPostProcessor
                                                                                       .CommonAnnotationBeanPostProcessor

org.springframework.  context.event.EventListenerMethodProcessor
                                                                            .DefaultEventListenerFactory

org.springframework.  beans.factory.annotation.AutowiredAnnotationBeanPostProcessor

과 같이 기본적으로 들어있는 빈들이 있음


3. 스프링 빈 조회( 기본, 동일타입 둘이상 )

 

 

4. 스프링 빈 조회( 상속 관계 )

 

5. xml 기반의 스프링 빈 설정정보

ApplicationContext ac = new GenericXmlApplicationContext("appConfig.xml");

 

이렇게 GenericXmlApplicationContext 을 이용하면 'xml설정정보' 로 스프링 컨테이너를 만들수도 있따

appConfig.xml 는 src / main / resources 에 만든다
( 아마 프로젝트의 classpath?가 resources 쪽에 연결되있어서, 자동으로 해당 경로 읽는듯? )

6. 스프링빈 설정 메타정보 - BeanDefinition

getBeanDefinition() 로 빈의 메타정보BeanDefinition를 얻을수 있음
여러가지 성질들이 있음