Spring's Special Beans
by , 11-16-2011 at 04:25 PM (705 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:
The postProcessBeforeInitialization() method is called immediately prior to bean initialization. Similarly, the postProcessAfterInitialization() method is called immediately after initialization.Java Code:public interface BeanPostProcessor { Object postProcessBeforeInitialization( Object bean, String name) throws BeansException; Object postProcessAfterInitialization( Object bean, String name) throws BeansException; }









Email Blog Entry
PDF to TIFF Conversion & Control...
Yesterday, 11:39 AM in Java Software