List of usage examples for org.springframework.beans.factory.support DefaultListableBeanFactory configureBean
@Override public Object configureBean(Object existingBean, String beanName) throws BeansException
From source file:org.springframework.beans.factory.DefaultListableBeanFactoryTests.java
@Test public void testConfigureBean() { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.add("age", "99"); RootBeanDefinition bd = new RootBeanDefinition(TestBean.class); bd.setPropertyValues(pvs);//from ww w.j a va 2 s . c o m lbf.registerBeanDefinition("test", bd); TestBean tb = new TestBean(); assertEquals(0, tb.getAge()); lbf.configureBean(tb, "test"); assertEquals(99, tb.getAge()); assertSame(lbf, tb.getBeanFactory()); assertNull(tb.getSpouse()); }
From source file:org.springframework.beans.factory.DefaultListableBeanFactoryTests.java
@Test public void testConfigureBeanWithAutowiring() { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); RootBeanDefinition bd = new RootBeanDefinition(TestBean.class); lbf.registerBeanDefinition("spouse", bd); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.add("age", "99"); RootBeanDefinition tbd = new RootBeanDefinition(TestBean.class); tbd.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_NAME); lbf.registerBeanDefinition("test", tbd); TestBean tb = new TestBean(); lbf.configureBean(tb, "test"); assertSame(lbf, tb.getBeanFactory()); TestBean spouse = (TestBean) lbf.getBean("spouse"); assertEquals(spouse, tb.getSpouse()); }