BeanPostProcessor . BeanPostProcessor gives you the ability to process the bean instance created by the IoC container after it is created, and then again after the initialization event occurs in the instance. You can use this to process the fields that have been set, perform a bean check, or even look for values ββfrom a remote resource to set to a bean by default.
BeanPostProcessors and any of the beans on which they depend are created before any other beans in the container. After they are created and ordered, they are used to process all other beans, since they are created by the IoC container. Spring various AOP proxies for caching, transactions, etc. all are applied by BeanPostProcessors. Thus, any BeanPostProcessor you created is not suitable for AOP proxies. Since AOP proxies are applied in this way, it is possible that the AOP proxy has not yet been applied to the instance, so care should be taken if this affects the execution of any subsequent processing.
init / destroy method . In Spring, you can use the init-method and destroy-method as an attribute in a bean configuration file for a bean to perform certain actions during initialization and destruction.
Here is an example to show you how to use the init-method and destroy-method.
package com.xyz.customer.services; public class CustomerService { String message; public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } public void initIt() throws Exception { System.out.println("Init method after properties are set : " + message); } public void cleanUp() throws Exception { System.out.println("Spring Container is destroy! Customer clean up"); } }
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="customerService" class="com.xyz.customer.services.CustomerService" init-method="initIt" destroy-method="cleanUp"> <property name="message" value="i'm property message" /> </bean>
kandarp Mar 26 2018-12-12T00: 00Z
source share