- BeanFactoryPostProcessor 类
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.stereotype.Component;
import java.util.Arrays;
@Component
public class MyBeanFactoryPostProcessor implements BeanFactoryPostProcessor {
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
System.out.println("MyBeanFactoryPostProcessor...postProcessBeanFactory...");
int count = beanFactory.getBeanDefinitionCount();
String[] names = beanFactory.getBeanDefinitionNames();
System.out.println("当前beanFactory中有"+count+" 个Bean");
System.out.println(Arrays.asList(names));
}
}
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@ComponentScan("com.fcc.springAnnotation.ext")
@Configuration
public class ExtConfig {
}
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
public class TestExt {
@Test
public void test01(){
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ExtConfig.class);
context.close();
}
}