
| Bean의 생성과 소멸 담당 |
| Bean을 생성 시 필요한 속성 설정 |
| Bean의 Life Cycle에 관련된 메소드 호출 |
| 다수의 BeanFactory 인터페이스 구현 클래스를 제공하며 이중 가장 유용한 것은 XmlBeanFactory임 |
| BeanFactory의 모든 기능 제공 |
| ResourceBundle 파일을 이용한 국제화(I18N) 지원 |
| 다양한 Resource 로딩 방법 제공 |
| 이벤트 핸들링 |
| Context 시작 시 모든 Singleton Bean을 미리 로딩(preloading) 시킴-> 초기에 설정 및 환경에 대한 에러 발견 가능함 |
| 다수의 ApplicationContext 구현 클래스 제공(XmlWebApplicationContext,FileSystemXmlApplicationContext,ClassPathXmlApplicationContext) |
BeanFactory factory = new XmlBeanFactory(new FileInputStream("beans.xml”));
| org.springframework.core.io.ByteArrayResource | Defines a resource whose content is given by an array of bytes |
| org.springframework.core.io.ClassPathResource | Defines a resource that is to be retrieved from the classpath |
| org.springframework.core.io.DescriptiveResource | Defines a resource that holds a resource description but no actual readable resource |
| org.springframework.core.io.FileSystemResource | Defines a resource that is to be retrieved from the file system |
| org.springframework.core.io.InputStreamResource | Defines a resource that is to be retrieved from an input stream |
| org.springframework.web.portlet.context.PortletContextResource | Defines a resource that is available in a portlet context |
| org.springframework.web.context.support.ServletContextResource | Defines a resource that is available in a servlet context |
| org.springframework.core.io.UrlResource | Defines a resource that is to be retrieved from a given URL |

ApplicationContext context = new FileSystemXmlApplicationContext("c:/foo.xml”);
ApplicationContext context = new ClassPathXmlApplicationContext("foo.xml”);
<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-2.5.xsd">
<bean id="..." class="...">
<!-- collaborators and configuration for this bean go here -->
</bean>
<!-- more bean definitions go here... -->
</beans>
Resource resource = new FileSystemResource("beans.xml");
BeanFactory factory = new XmlBeanFactory(resource);
ClassPathResource resource = new ClassPathResource("beans.xml");
BeanFactory factory = new XmlBeanFactory(resource);
ApplicationContext context = new ClassPathXmlApplicationContext(
new String[] {"applicationContext.xml", "applicationContext-part2.xml"});
// of course, an ApplicationContext is just a BeanFactory
BeanFactory factory = (BeanFactory) context;
<beans> <import resource="services.xml"/> <import resource="resources/messageSource.xml"/> <import resource="/resources/themeSource.xml"/> <bean id="bean1" class="..."/> <bean id="bean2" class="..."/> </beans>
| id | Bean의 구분을 위한 정보로 해당 bean에 접근하기 위한 Key임 |
| class | 정의된 Bean의 실제 구현클래스로 항상 full name으로 작성 |
| singleton | true/false 값을 가지며 해당 bean을 singleton으로 유지할 것인지 여부를 결정함. Default는 true이며 false일 경우, getBean() 메소드 사용하여 사용할 때 마다 해당 bean 객체 생성됨 |
| init-method | 해당 bean이 초기화된 후 context에 저장되기 전 호출되는 초기화 메소드 정의 |
| destroy-method | 해당 bean 제거 시 호출되는 메소드 정의 |
| factory-method | 해당 bean 생성 시 생성자를 사용하지 않고 특정 factory method를 호출하여 생성 시 정의 |
| lazy-init | true/false 값을 가지며 해당 bean이 호출되기 전에 초기화 시킬지 여부를 결정함. Default는 false이며 true인 경우, 해당 bean이 호출되는 시점에 초기화시킴 |
<bean id="exampleBean" class="examples.ExampleBean"/> <bean name="anotherExample" class="examples.ExampleBeanTwo"/>
<bean id="exampleBean" class="examples.ExampleBean2" factory-method="createInstance"/>
<!-- the factory bean, which contains a method called createInstance() --> <bean id="myFactoryBean" class="..."/> <!-- the bean to be created via the factory bean --> <bean id="exampleBean" factory-bean="myFactoryBean" factory-method="createInstance"/>