@Component
public class MyBeanFactoryPostProcessor2 implements BeanDefinitionRegistryPostProcessor{
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
// TODO Auto-generated method stub
}
//可以动态把对象注入spring对象
@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
for (int i = 0; i < 10; i++) {
BeanDefinitionBuilder b=BeanDefinitionBuilder.rootBeanDefinition(User.class);
b.addPropertyValue("name", "admin"+i);
registry.registerBeanDefinition("user"+i, b.getBeanDefinition());
}
}
}