package autopackage;
import org.springframework.beans.BeansException;
import org.springframework.beans.PropertyValues;
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessorAdapter;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Constructor;
public class PersonInstantiationAwareBeanPostProcessor extends InstantiationAwareBeanPostProcessorAdapter {
public PersonInstantiationAwareBeanPostProcessor() {
super();
System.out.println("I'm the PersonInstantiationAwareBeanPostProcessor");
}
@Override
public Class<?> predictBeanType(Class<?> beanClass, String beanName) {
return super.predictBeanType(beanClass, beanName);
}
@Override
public Constructor<?>[] determineCandidateConstructors(Class<?> beanClass, String beanName) throws BeansException {
return super.determineCandidateConstructors(beanClass, beanName);
}
@Override
public Object getEarlyBeanReference(Object bean, String beanName) throws BeansException {
return super.getEarlyBeanReference(bean, beanName);
}
@Override
public Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException {
if (beanClass.equals(Person.class)) {
System.out.println("I'm the PersonInstantiationAwareBeanPostProcessor.postProcessBeforeInstantiation");
}
return super.postProcessBeforeInstantiation(beanClass, beanName);
}
@Override
public boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException {
if (bean instanceof Person) {
System.out.println("I'm the PersonInstantiationAwareBeanPostProcessor.postProcessAfterInstantiation");
}
return super.postProcessAfterInstantiation(bean, beanName);
}
@Override
public PropertyValues postProcessPropertyValues(PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) throws BeansException {
if (bean instanceof Person) {
System.out.println("I'm the PersonInstantiationAwareBeanPostProcessor.postProcessPropertyValues");
}
return super.postProcessPropertyValues(pvs, pds, bean, beanName);
}
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof Person) {
System.out.println("I'm the PersonInstantiationAwareBeanPostProcessor.postProcessBeforeInitialization");
}
return super.postProcessBeforeInitialization(bean, beanName);
}
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof Person) {
System.out.println("I'm the PersonInstantiationAwareBeanPostProcessor.postProcessAfterInitialization");
}
return super.postProcessAfterInitialization(bean, beanName);
}
}