Spring Bean
Introduction
Bean is an object which is managed by Spring IOC Container.IOC Container is of two types:
1) Bean Factory
• It is an interface and its implemented class is XmlBeanFactory.
• It creates the objects on demand.
• When getBean() method is called, an object gets created.
• It is also called Lazy Container.
• The default scope is Singleton, means only one bean object is created. No matter how many times you call getBean(), the same bean object will be returned.
• It doesn't support I18N.
2) ApplicationContext
• It is an interface and the implemented class is ClassPathXmlApplicationContext.
• It creates objects at the time of loading of xml file.
• It is also called an early or eager container.
• The default scope is Singleton.
• If the scope is prototype, at that time, it works same as BeanFactory. It means it creates the object at the time of user request and not at the time of loading.
Bean Scopes
Bean Scopes have two types:• Singleton:
It has default scope.
It creates only one object for the whole application.
• Prototype
For every request, it creates a new object.
Life Cycle

Spring Framework provides 2 marker interfaces:
• InitializingBean
afterPropertiesSet() for initialization
• DisposableBean
destroy() for destruction
No comments:
Post a Comment