Java/Framework & Libs
XML로 만든 빈 설정 메타정보
허니몬
2011. 4. 4. 10:48
/springbook/etc/testGenericApplicactionContext.xml
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
- <bean id="hello" class="springbook.etc.Hello">
- <property name="name" value="Spring" />
- <property name="printer" ref="printer" />
- </bean>
- <bean id="printer" class="springbook.etc.StringPrinter" />
- </beans>
GenericApplicationContext의 사용방법에 대한 학습 테스트
- @Test
- public void testGenericApplicationContext(){
- GenericApplicationContext ac = new GenericApplicationContext();
- XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ac);
- //XmlBeanDefinitionReader는 기본적으로 클래스패스로 정의돈 리소스로부터 파일을 읽는다.
- reader.loadBeanDefinitions("springbook/etc/testGenericApplicactionContext.xml");
- //모든 메타정보 등록이 완료됐으니 애플리케이션 컨테이너를 초기화하라는 명령이다.
- ac.refresh();
- Hello hello = ac.getBean("hello", Hello.class);
- hello.print();
- assertThat(ac.getBean("printer").toString(), is("Hello Spring"));
- }
이 글은 스프링노트에서 작성되었습니다.