ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • BeanDefinition
    카테고리 없음 2023. 4. 18. 12:30

    BeanDefinition

    스프링의 설정 메타 정보는 XML 파일이 아니다. 스프링에 대한 대표적인 오해 중의 하나는 스프링의 설정정보는 XML로 되어있다. 스프링이 XML에 담긴 내용을 읽어서 설정 메타정보를 활용하는 것은 사실이지만 그렇다고 해서 스프링이 XML로 된 설정 메타정보를 가졌다는 말은 틀렸다. 스프링의 설정 메타정보는 BeanDefinition 인터페이스로 표현되는 순수한 추상 정보다. 스프링 IoC 컴테이너, 즉 애플리케이션 컨텍스트는 바로 BeanDefinition 으로 만들어진 메타정보를 담은 오브젝트를 사용해 IoC와 DI 작업을 수행한다.
    BeanDefinition helloDef =new RootBeanDefinition(Hello.class); 
    helloDef.getPropertyValues().addPropertyValue("name","Spring");
    ac.registerBeanDefinition("hello2", helloDef);
    
    Hello hello2 = ac.getBean("hello2", Hello.class);
    
    StaticApplicationContext ac =new StaticApplicationContext();
    ac.registerBeanDefinition("printer" ,new RootBeanDefinition(StringPrinter.class));
    BeanDefinition helloDef =new RootBeanDefinition(Hello.class);
    helloDef.getPropertyValues().addPropertyValue("name", "Spring");
    helloDef.getPropertyValues().addPropertyValue("printer",new RuntimeBeanReference("printer"));                   
    
    ac.registerBeanDefinition("hello", helloDef); 
    Hello hello =ac.getBean("hello", Hello.class);
    hello.print();
    System.out.println(ac.getBean("printer").toString()); //Hello Spring
    
    토비느님의책중..

    댓글

Designed by Tistory.