Example usage for org.springframework.beans.factory.support DefaultListableBeanFactory applyBeanPropertyValues

List of usage examples for org.springframework.beans.factory.support DefaultListableBeanFactory applyBeanPropertyValues

Introduction

In this page you can find the example usage for org.springframework.beans.factory.support DefaultListableBeanFactory applyBeanPropertyValues.

Prototype

@Override
    public void applyBeanPropertyValues(Object existingBean, String beanName) throws BeansException 

Source Link

Usage

From source file:org.springframework.beans.factory.DefaultListableBeanFactoryTests.java

@Test
public void testApplyBeanPropertyValues() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.add("age", "99");
    RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
    bd.setPropertyValues(pvs);//from  w w w  .  j ava2 s.co  m
    lbf.registerBeanDefinition("test", bd);
    TestBean tb = new TestBean();
    assertEquals(0, tb.getAge());
    lbf.applyBeanPropertyValues(tb, "test");
    assertEquals(99, tb.getAge());
}

From source file:org.springframework.beans.factory.DefaultListableBeanFactoryTests.java

@Test
public void testApplyBeanPropertyValuesWithIncompleteDefinition() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    MutablePropertyValues pvs = new MutablePropertyValues();
    pvs.add("age", "99");
    RootBeanDefinition bd = new RootBeanDefinition();
    bd.setPropertyValues(pvs);//  www.  j  a va  2  s.co  m
    lbf.registerBeanDefinition("test", bd);
    TestBean tb = new TestBean();
    assertEquals(0, tb.getAge());
    lbf.applyBeanPropertyValues(tb, "test");
    assertEquals(99, tb.getAge());
    assertNull(tb.getBeanFactory());
    assertNull(tb.getSpouse());
}