spring复习:(23)DefaultListableBeanFactory BeanPostProcessor不起作用

配置文件:




    

    

    

    


package cn.edu.tju;

import cn.edu.tju.domain.MyInitObject;
import cn.edu.tju.domain.MyPostProcessObject;
import cn.edu.tju.domain.Student;
import org.springframework.beans.factory.support.BeanDefinitionReader;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

import java.util.concurrent.locks.ReentrantLock;

public class Start16 {
    public static void main(String[] args) {
        Resource resource = new ClassPathResource("beans13.xml");
        DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
        BeanDefinitionReader beanDefinitionReader = new XmlBeanDefinitionReader(factory);
        beanDefinitionReader.loadBeanDefinitions(resource);

        //ApplicationContext factory = new ClassPathXmlApplicationContext("beans13.xml");

        MyInitObject student = factory.getBean("tju", MyInitObject.class);



    }
}

这样写BeanPostProcessor的代码不执行。换成ApplicationContext的写法就可以。debug发现:用DefaultListableBeanFactory时,

	public List getBeanPostProcessors() {
		return this.beanPostProcessors;
	}

这个方法返回的list 的size为0

你可能感兴趣的:(Spring,spring,java,后端)