public class ConfigTest {
@PostConstruct
public void testgfhd(){
System.out.println("-111");
}
}
public class Vd {
@PostConstruct
public void testdgg(){
System.out.println("22");
}
}
@Configuration
public class MyBeanFactoryPostProcessor implements BeanDefinitionRegistryPostProcessor {
@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
AbstractBeanDefinition beanDefinition1 = BeanDefinitionBuilder.genericBeanDefinition().getBeanDefinition();
beanDefinition1.setBeanClass(Vd.class);
registry.registerBeanDefinition("vd",beanDefinition1);
AbstractBeanDefinition beanDefinition2 = BeanDefinitionBuilder.genericBeanDefinition().getBeanDefinition();
beanDefinition2.setBeanClass(ConfigTest.class);
registry.registerBeanDefinition("configTest",beanDefinition2);
//相当于往Spring容器初始化的时的那个List里面添加了一个Bean 只要在扫描之前执行了postProcessBeanDefinitionRegistry 方法 那么就会安装List里面存放的顺序
//生成Bean
}
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
}
}
标签:先后顺序,springboot,void,beanDefinition1,beanDefinition2,public,bean,registry,class From: https://www.cnblogs.com/skww/p/18353139