Java Code Examples for org.springframework.beans.factory.support.RootBeanDefinition#setAbstract()

The following examples show how to use org.springframework.beans.factory.support.RootBeanDefinition#setAbstract() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultListableBeanFactoryTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testCanReferenceParentBeanFromChildViaAlias() {
	final String EXPECTED_NAME = "Juergen";
	final int EXPECTED_AGE = 41;

	RootBeanDefinition parentDefinition = new RootBeanDefinition(TestBean.class);
	parentDefinition.setAbstract(true);
	parentDefinition.getPropertyValues().add("name", EXPECTED_NAME);
	parentDefinition.getPropertyValues().add("age", EXPECTED_AGE);

	ChildBeanDefinition childDefinition = new ChildBeanDefinition("alias");

	DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
	factory.registerBeanDefinition("parent", parentDefinition);
	factory.registerBeanDefinition("child", childDefinition);
	factory.registerAlias("parent", "alias");

	TestBean child = (TestBean) factory.getBean("child");
	assertEquals(EXPECTED_NAME, child.getName());
	assertEquals(EXPECTED_AGE, child.getAge());

	assertEquals("Use cached merged bean definition",
			factory.getMergedBeanDefinition("child"), factory.getMergedBeanDefinition("child"));
}
 
Example 2
Source File: DefaultListableBeanFactoryTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testCanReferenceParentBeanFromChildViaAlias() {
	final String EXPECTED_NAME = "Juergen";
	final int EXPECTED_AGE = 41;

	RootBeanDefinition parentDefinition = new RootBeanDefinition(TestBean.class);
	parentDefinition.setAbstract(true);
	parentDefinition.getPropertyValues().add("name", EXPECTED_NAME);
	parentDefinition.getPropertyValues().add("age", EXPECTED_AGE);

	ChildBeanDefinition childDefinition = new ChildBeanDefinition("alias");

	DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
	factory.registerBeanDefinition("parent", parentDefinition);
	factory.registerBeanDefinition("child", childDefinition);
	factory.registerAlias("parent", "alias");

	TestBean child = (TestBean) factory.getBean("child");
	assertEquals(EXPECTED_NAME, child.getName());
	assertEquals(EXPECTED_AGE, child.getAge());

	assertEquals("Use cached merged bean definition",
			factory.getMergedBeanDefinition("child"), factory.getMergedBeanDefinition("child"));
}
 
Example 3
Source File: DefaultListableBeanFactoryTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testCanReferenceParentBeanFromChildViaAlias() {
	final String EXPECTED_NAME = "Juergen";
	final int EXPECTED_AGE = 41;

	RootBeanDefinition parentDefinition = new RootBeanDefinition(TestBean.class);
	parentDefinition.setAbstract(true);
	parentDefinition.getPropertyValues().add("name", EXPECTED_NAME);
	parentDefinition.getPropertyValues().add("age", EXPECTED_AGE);

	ChildBeanDefinition childDefinition = new ChildBeanDefinition("alias");

	DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
	factory.registerBeanDefinition("parent", parentDefinition);
	factory.registerBeanDefinition("child", childDefinition);
	factory.registerAlias("parent", "alias");

	TestBean child = (TestBean) factory.getBean("child");
	assertEquals(EXPECTED_NAME, child.getName());
	assertEquals(EXPECTED_AGE, child.getAge());

	assertEquals("Use cached merged bean definition",
			factory.getMergedBeanDefinition("child"), factory.getMergedBeanDefinition("child"));
}
 
Example 4
Source File: DefaultListableBeanFactoryTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testGetTypeForAbstractFactoryBean() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	RootBeanDefinition bd = new RootBeanDefinition(FactoryBeanThatShouldntBeCalled.class);
	bd.setAbstract(true);
	lbf.registerBeanDefinition("factoryBean", bd);
	assertNull(lbf.getType("factoryBean"));
}
 
Example 5
Source File: DefaultListableBeanFactoryTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testGetTypeForAbstractFactoryBean() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	RootBeanDefinition bd = new RootBeanDefinition(FactoryBeanThatShouldntBeCalled.class);
	bd.setAbstract(true);
	lbf.registerBeanDefinition("factoryBean", bd);
	assertNull(lbf.getType("factoryBean"));
}
 
Example 6
Source File: DefaultListableBeanFactoryTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetTypeForAbstractFactoryBean() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	RootBeanDefinition bd = new RootBeanDefinition(FactoryBeanThatShouldntBeCalled.class);
	bd.setAbstract(true);
	lbf.registerBeanDefinition("factoryBean", bd);
	assertNull(lbf.getType("factoryBean"));
}