@ComponentScan({"com.ghc.springlearning.MyPostProcessors.components"})
@Configuration
public class Bean1 {
@Bean(initMethod = "init")
public Bean4 bean4(){
return new Bean4();
}
@Bean
public Bean5 bean5(){
return new Bean5();
}
}
Bean4
public class Bean4 {
public void init(){
System.out.println("bean4 初始化");
}
}
编写自定义BeanFactory后处理器实现接口
public class AtBeanPostProcessor implements BeanFactoryPostProcessor {
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException {
DefaultListableBeanFactory beanFactory=(DefaultListableBeanFactory) configurableListableBeanFactory;
CachingMetadataReaderFactory readerFactory = new Ca