Spring IOC Container
========================================
-> The Spring container is at the core of the Spring Framework.
-> The container will create the objects, wire them together, configure them and manage their complete lifecycle from creation till destruction.
-> IOC Container that contains beans and their configurations to develop mutiple types of applications. Such as standard applications, web applications,
and enterprise applications.
-> IOC Container says that you don't bother about object creation or you don't create your objects only describe how they should be created.
-> IOC Container also says you don't directly connect your components and services together in code but only describe which services are needed by which components in a configuration file.
Benefits of IOC Container:
=========================
-> Minimize the amount of code in our application.
-> Provides Loose coupling between components in application.
-> If any modification have to do then it doesn't affect other components.
-> There are two ways of defining IOC Container:
1. BeanFactory Container
2. ApplicationContext Container
BeanFactory Container
-----------------------------------
-> A BeanFactory is like a factory class that contains a collection of beans.
-> The BeanFactory holds Beans definitions of multiple beans within itself and then instantiates the bean whenever asked for by clients.
-> If we are developing small scale applications likes mobile applications, Embedded System applications then we use BeanFactory because few extra KBs are also matters towards application size.
-> There are several implementation of BeanFactory. The most useful one is "XmlBeanFactory".
eg: BeanFactory factory=new XmlBeanFactory(new FileInputStream("mybean.xml"));
ApplicationContext Container
--------------------------------------
-> A BeanFactory is fine to simple applications but to take advantage of the full power of the Spring framework, we may want to move up to Spring's more advanced container, the ApplicationContext.
-> If we are developing enterprise applications (like web applications, distributed applications) then use ApplicationContext container.
-> Both are same but it has some extra advantage: For example:
1. Support Internationalization or I18n.
2. Publish or processing events to beans and event handling.
3. Ability to work with Properties file.
4. Pre-instantiation of singleton spring bean.
5. Supports Automatic registration of bean post processor.
6. Provides to stop or close the container.
The Three implementation of ApplicationContext are:
1. ClassPathXmlApplicationContext eg: ApplicationContext ctx=new ClassPathXmlApplicationContext("bean.xml");
2. FileSystemXmlApplicationContext eg: ApplicationContext ctx=new FileSystemXmlApplicationContext("bean.xml");
3. XmlWebApplicationContext
Comments
Post a Comment