BeanPostProcessor를 구현하게 되면 lazy-init 속성은 무시된다
Bean의 삭제 과정
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
public class PersonBean implements InitializingBean,DisposableBean{
private String name;
public PersonBean() {
System.out.println("Constructor of person bean is called !! ");
}
@Override
public void destroy() throws Exception {
System.out.println("destroy method of person bean is called !! ");
}
@Override
public void afterPropertiesSet() throws Exception {
System.out.println("afterPropertiesSet method of person bean is called !! ");
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
import java.util.Arrays;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
public class AwareBean implements ApplicationContextAware,BeanNameAware,BeanFactoryAware {
@Override
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
System.out.println("setBeanFactory method of Aware bean is called");
System.out.println("setBeanFactory:: Aware bean singleton=" + beanFactory.isSingleton("awareBean"));
}
@Override
public void setBeanName(String beanName) {
System.out.println("setBeanName method of Aware bean is called");
System.out.println("setBeanName:: Bean Name defined in context=" + beanName);
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
System.out.println("setApplicationContext method of Aware bean is called");
System.out.println("setApplicationContext:: Bean Definition Names=" + Arrays.toString(applicationContext.getBeanDefinitionNames()));
}
}
<bean id="customLifeCycleMethodBean" class="CustomLifeCycleMethodBean"
init-method="customInit"
destroy-method="customDestroy">
<property name="name" value="custom methods bean" ></property>
</bean>
-----------------------------------------------------------------------
public class CustomLifeCycleMethodBean {
private String name;
public CustomLifeCycleMethodBean() {
System.out.println("Constructor of bean is called !! ");
}
public void customDestroy() throws Exception {
System.out.println("custom destroy method of bean is called !! ");
}
public void customInit() throws Exception {
System.out.println("custom Init method of bean is called !! ");
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}