View RSS Feed

Spring Framework

Spring's Special Beans

Rate this Entry
by , 11-16-2011 at 05:25 PM (1277 Views)
The majority of beans in Spring are configured by the Spring container and made available for use in the application. Apart from these standard beans, Spring also has groups of beans that each serve a special purpose. The way in which Spring identifies these beans is because these beans have implemented certain interfaces that Spring considers special. The use of these interfaces allows these beans to do the following:
  • Post processing bean configuration in order to be involved in the bean factoryís life cycle beanís as well as the life cycle of the bean
  • Load configuration information from external property files
  • Change Springís dependency injection to automatically convert String values to another type when setting bean properties. So for example you can inject a String value for a Date field and the value will be automatically converted to java.util.Date
  • Load textual messages from property files (this includes internationalized messages)
  • Listen and respond to application events that are published by the Spring container and other beans
  • Be self-aware of their own identity within the Spring container

One of the Springís special beans that perform post-processing of other beans and of the bean factory itself. This allows your bean to cut into a beanís life cycle and review or alter its configuration. The event this post-processing follows is the instantiation and configuring of a bean. The BeanPostProcessor interface gives two methods that can be used to alter a bean after it has been created and wired:

Java Code:
public interface BeanPostProcessor { 
	Object postProcessBeforeInitialization(
		Object bean, String name) throws BeansException;

	Object postProcessAfterInitialization( Object bean, 
		String name) throws BeansException;
The postProcessBeforeInitialization() method is called immediately prior to bean initialization. Similarly, the postProcessAfterInitialization() method is called immediately after initialization.

Submit "Spring's Special Beans" to Facebook Submit "Spring's Special Beans" to Digg Submit "Spring's Special Beans" to Submit "Spring's Special Beans" to StumbleUpon Submit "Spring's Special Beans" to Google

Bean , Configuration , XML