org.springframework.beans.factory.support.BeanDefinitionOverrideException Java Examples

The following examples show how to use org.springframework.beans.factory.support.BeanDefinitionOverrideException. 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 testBeanDefinitionOverridingNotAllowed() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	lbf.setAllowBeanDefinitionOverriding(false);
	BeanDefinition oldDef = new RootBeanDefinition(TestBean.class);
	BeanDefinition newDef = new RootBeanDefinition(NestedTestBean.class);
	lbf.registerBeanDefinition("test", oldDef);
	try {
		lbf.registerBeanDefinition("test", newDef);
		fail("Should have thrown BeanDefinitionOverrideException");
	}
	catch (BeanDefinitionOverrideException ex) {
		assertEquals("test", ex.getBeanName());
		assertSame(newDef, ex.getBeanDefinition());
		assertSame(oldDef, ex.getExistingDefinition());
	}
}
 
Example #2
Source File: DefaultListableBeanFactoryTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testBeanDefinitionOverridingNotAllowed() {
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	lbf.setAllowBeanDefinitionOverriding(false);
	BeanDefinition oldDef = new RootBeanDefinition(TestBean.class);
	BeanDefinition newDef = new RootBeanDefinition(NestedTestBean.class);
	lbf.registerBeanDefinition("test", oldDef);
	try {
		lbf.registerBeanDefinition("test", newDef);
		fail("Should have thrown BeanDefinitionOverrideException");
	}
	catch (BeanDefinitionOverrideException ex) {
		assertEquals("test", ex.getBeanName());
		assertSame(newDef, ex.getBeanDefinition());
		assertSame(oldDef, ex.getExistingDefinition());
	}
}
 
Example #3
Source File: ProjectGeneratorTests.java    From initializr with Apache License 2.0 5 votes vote down vote up
@Test
void generateDoesNotAllowBeanDefinitionOverridingByDefault() {
	ProjectGenerator generator = new ProjectGenerator((context) -> {
		context.registerBean("testBean", String.class, () -> "test");
		context.registerBean("testBean", String.class, () -> "duplicate");
	});
	ProjectAssetGenerator<?> assetGenerator = mock(ProjectAssetGenerator.class);
	assertThatThrownBy(() -> generator.generate(new MutableProjectDescription(), assetGenerator))
			.isInstanceOf(BeanDefinitionOverrideException.class).hasMessageContaining("testBean");
}