Examples of autowire()


Examples of org.springframework.beans.factory.support.DefaultListableBeanFactory.autowire()

    RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
    lbf.registerBeanDefinition("rod", bd);
    RootBeanDefinition bd2 = new RootBeanDefinition(TestBean.class);
    lbf.registerBeanDefinition("rod2", bd2);
    try {
      lbf.autowire(ConstructorDependency.class, AutowireCapableBeanFactory.AUTOWIRE_AUTODETECT, false);
      fail("Should have thrown UnsatisfiedDependencyException");
    }
    catch (UnsatisfiedDependencyException ex) {
      // expected
      assertTrue(ex.getMessage().indexOf("rod") != -1);
View Full Code Here

Examples of org.springframework.beans.factory.support.DefaultListableBeanFactory.autowire()

    pvs.addPropertyValue(new PropertyValue("name", "Rod"));
    RootBeanDefinition bd = new RootBeanDefinition(TestBean.class, pvs);
    lbf.registerBeanDefinition("rod", bd);
    assertEquals(1, lbf.getBeanDefinitionCount());
    try {
      lbf.autowire(UnsatisfiedConstructorDependency.class, AutowireCapableBeanFactory.AUTOWIRE_AUTODETECT, true);
      fail("Should have unsatisfied constructor dependency on SideEffectBean");
    }
    catch (UnsatisfiedDependencyException ex) {
      // expected
    }
View Full Code Here

Examples of org.springframework.beans.factory.support.DefaultListableBeanFactory.autowire()

  public void testAutowireConstructor() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    RootBeanDefinition bd = new RootBeanDefinition(TestBean.class, new MutablePropertyValues());
    lbf.registerBeanDefinition("spouse", bd);
    ConstructorDependenciesBean bean = (ConstructorDependenciesBean)
        lbf.autowire(ConstructorDependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, true);
    Object spouse = lbf.getBean("spouse");
    assertTrue(bean.getSpouse1() == spouse);
    assertTrue(BeanFactoryUtils.beanOfType(lbf, TestBean.class) == spouse);
  }
View Full Code Here

Examples of org.springframework.beans.factory.support.DefaultListableBeanFactory.autowire()

  public void testAutowireBeanByName() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    RootBeanDefinition bd = new RootBeanDefinition(TestBean.class, new MutablePropertyValues());
    lbf.registerBeanDefinition("spouse", bd);
    DependenciesBean bean = (DependenciesBean)
        lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, true);
    TestBean spouse = (TestBean) lbf.getBean("spouse");
    assertEquals(spouse, bean.getSpouse());
    assertTrue(BeanFactoryUtils.beanOfType(lbf, TestBean.class) == spouse);
  }
View Full Code Here

Examples of org.springframework.beans.factory.support.DefaultListableBeanFactory.autowire()

  public void testAutowireBeanByNameWithDependencyCheck() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    RootBeanDefinition bd = new RootBeanDefinition(TestBean.class, new MutablePropertyValues());
    lbf.registerBeanDefinition("spous", bd);
    try {
      lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, true);
      fail("Should have thrown UnsatisfiedDependencyException");
    }
    catch (UnsatisfiedDependencyException ex) {
      // expected
    }
View Full Code Here

Examples of org.springframework.beans.factory.support.DefaultListableBeanFactory.autowire()

  public void testAutowireBeanByNameWithNoDependencyCheck() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    RootBeanDefinition bd = new RootBeanDefinition(TestBean.class, new MutablePropertyValues());
    lbf.registerBeanDefinition("spous", bd);
    DependenciesBean bean = (DependenciesBean)
        lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false);
    assertNull(bean.getSpouse());
  }

  public void testAutowireBeanByType() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
View Full Code Here

Examples of org.springframework.beans.factory.support.DefaultListableBeanFactory.autowire()

  public void testAutowireBeanByType() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    RootBeanDefinition bd = new RootBeanDefinition(TestBean.class, new MutablePropertyValues());
    lbf.registerBeanDefinition("test", bd);
    DependenciesBean bean = (DependenciesBean)
        lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
    TestBean test = (TestBean) lbf.getBean("test");
    assertEquals(test, bean.getSpouse());
  }

  /**
 
View Full Code Here

Examples of org.springframework.beans.factory.support.DefaultListableBeanFactory.autowire()

    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    RootBeanDefinition bd = new RootBeanDefinition(LazyInitFactory.class, new MutablePropertyValues());
    lbf.registerBeanDefinition("factoryBean", bd);
    LazyInitFactory factoryBean = (LazyInitFactory) lbf.getBean("&factoryBean");
    assertNotNull("The FactoryBean should have been registered.", factoryBean);
    FactoryBeanDependentBean bean = (FactoryBeanDependentBean) lbf.autowire(FactoryBeanDependentBean.class,
        AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
    assertEquals("The FactoryBeanDependentBean should have been autowired 'by type' with the LazyInitFactory.",
        factoryBean, bean.getFactoryBean());
  }
View Full Code Here

Examples of org.springframework.beans.factory.support.DefaultListableBeanFactory.autowire()

        DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
        RootBeanDefinition bd = new RootBeanDefinition(LazyInitFactory.class, new MutablePropertyValues());
        lbf.registerBeanDefinition("factoryBean", bd);
        LazyInitFactory factoryBean = (LazyInitFactory) lbf.getBean("&factoryBean");
        assertNotNull("The FactoryBean should have been registered.", factoryBean);
        lbf.autowire(FactoryBeanDependentBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, true);
      }
    }.runTest();
  }

  public void testAutowireBeanByTypeWithTwoMatches() {
View Full Code Here

Examples of org.springframework.beans.factory.support.DefaultListableBeanFactory.autowire()

    RootBeanDefinition bd = new RootBeanDefinition(TestBean.class, new MutablePropertyValues());
    RootBeanDefinition bd2 = new RootBeanDefinition(TestBean.class, new MutablePropertyValues());
    lbf.registerBeanDefinition("test", bd);
    lbf.registerBeanDefinition("test2", bd2);
    try {
      lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
      fail("Should have thrown UnsatisfiedDependencyException");
    }
    catch (UnsatisfiedDependencyException ex) {
      // expected
      assertTrue(ex.getMessage().indexOf("test") != -1);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.