10-beanDefinition方式如何完成属性注入

实现BeanFactoryPostProcessor接口, 为某个指定的bean设置属性PropertyValues,
当然这个类有BeanDefinitionPropertyValuesBeanTest的setter()
popluateBean()中会调用setter方法将属性设置到变量中
if (pvs != null) { //完成自动注入 applyPropertyValues(beanName, mbd, bw, pvs); }

@Component
public class UpdateBeanInfoBeanFactoryPostProcessor implements BeanFactoryPostProcessor{
	@Override
	public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
		AbstractBeanDefinition a = (AbstractBeanDefinition) beanFactory.getBeanDefinition("a");
		//a.setAutowireMode(2);
		a.getPropertyValues().add("beanDefinitionPropertyValuesBeanTest",new BeanDefinitionPropertyValuesBeanTest());
	}
}

你可能感兴趣的:(spring,java,spring,开发语言)