首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

施用编码方式创建和绑定Bean

2012-07-01 
使用编码方式创建和绑定Bean?//创建Bean工厂DefaultListableBeanFactory factory new DefaultListableBe

使用编码方式创建和绑定Bean

?

//创建Bean工厂DefaultListableBeanFactory factory = new DefaultListableBeanFactory();//生成BeanDefinitionAbstractBeanDefinition newA = new RootBeanDefinition(A.class);newA.setScope(BeanDefinition.SCOPE_SINGLETON);AbstractBeanDefinition newB = new RootBeanDefinition(B.class);newB.setScope(BeanDefinition.SCOPE_PROTOTYPE);//注册factory.registerBeanDefinition("a", newA);factory.registerBeanDefinition("b", newB);//功过构造函数注入ConstructorArgumentValues argValues = new ConstructorArgumentValues();argValues.addIndexedArgumentValue(0, newB);newA.setConstructorArgumentValues(argValues);//通过Setter方式注入MutablePropertyValues propertyValues = new MutablePropertyValues();propertyValues.addPropertyValue(new PropertyValue("b", newB));newA.setPropertyValues(propertyValues);A a = (A) factory.getBean("a");a.getB().output();

?

?

?

?

?

?

?

?

热点排行