Notice: Undefined variable: footnotelist in /home/javawith/public_html/codesjava.com/wp-content/plugins/latex2html/inc/core.php on line 475
Spring IoC container is responsible for create, wire, configure and manage objects during their complete life cycle. It uses configuration metadata for create, configure and manage objects. Configuration metadata can be represented by spring configuration xml file or annotations.
Types of Spring IoC container:
BeanFactory org.springframework.beans.factory.BeanFactory is the interface and XmlBeanFactory is an implementation class of it. It is a simple container which provides the basic support for dependency injection.
Syntax to use BeanFactory:
Resource resource = new ClassPathResource(“spring configuration file”); BeanFactory beanFactory = new XmlBeanFactory(resource);
ApplicationContext org.springframework.context.ApplicationContext is the interface and ClassPathXmlApplicationContext is an implementation class of it. ApplicationContext container includes all functionality of the BeanFactory container with some extra functionality like internationalization, event listeners etc.
Syntax to use ApplicationContext:
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring configuration file");
Note: As ApplicationContext provides extra functionality including all given by BeanFactory it is better to use ApplicationContext container.