use of org.springframework.beans.factory.UnsatisfiedDependencyException in project spring-framework by spring-projects.
the class ComponentScanParserBeanDefinitionDefaultsTests method testAutowireByType.
@Test
public void testAutowireByType() {
GenericApplicationContext context = new GenericApplicationContext();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultAutowireByTypeTests.xml");
try {
context.refresh();
fail("expected exception due to multiple matches for byType autowiring");
} catch (UnsatisfiedDependencyException ex) {
// expected
}
}
use of org.springframework.beans.factory.UnsatisfiedDependencyException in project spring-framework by spring-projects.
the class AutowiredAnnotationBeanPostProcessorTests method testCustomAnnotationOptionalMethodResourceInjectionWhenMultipleDependenciesFound.
@Test
public void testCustomAnnotationOptionalMethodResourceInjectionWhenMultipleDependenciesFound() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
bpp.setAutowiredAnnotationType(MyAutowired.class);
bpp.setRequiredParameterName("optional");
bpp.setRequiredParameterValue(false);
bpp.setBeanFactory(bf);
bf.addBeanPostProcessor(bpp);
bf.registerBeanDefinition("customBean", new RootBeanDefinition(CustomAnnotationOptionalMethodResourceInjectionBean.class));
TestBean tb1 = new TestBean();
bf.registerSingleton("testBean1", tb1);
TestBean tb2 = new TestBean();
bf.registerSingleton("testBean2", tb2);
try {
bf.getBean("customBean");
fail("Should have thrown UnsatisfiedDependencyException");
} catch (UnsatisfiedDependencyException ex) {
// expected
assertSame(CustomAnnotationOptionalMethodResourceInjectionBean.class, ex.getInjectionPoint().getMethodParameter().getDeclaringClass());
}
bf.destroySingletons();
}
use of org.springframework.beans.factory.UnsatisfiedDependencyException in project spring-framework by spring-projects.
the class AutowiredAnnotationBeanPostProcessorTests method testCustomAnnotationRequiredFieldResourceInjectionFailsWhenMultipleDependenciesFound.
@Test
public void testCustomAnnotationRequiredFieldResourceInjectionFailsWhenMultipleDependenciesFound() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
bpp.setAutowiredAnnotationType(MyAutowired.class);
bpp.setRequiredParameterName("optional");
bpp.setRequiredParameterValue(false);
bpp.setBeanFactory(bf);
bf.addBeanPostProcessor(bpp);
bf.registerBeanDefinition("customBean", new RootBeanDefinition(CustomAnnotationRequiredFieldResourceInjectionBean.class));
TestBean tb1 = new TestBean();
bf.registerSingleton("testBean1", tb1);
TestBean tb2 = new TestBean();
bf.registerSingleton("testBean2", tb2);
try {
bf.getBean("customBean");
fail("Should have thrown UnsatisfiedDependencyException");
} catch (UnsatisfiedDependencyException ex) {
// expected
assertSame(CustomAnnotationRequiredFieldResourceInjectionBean.class, ex.getInjectionPoint().getField().getDeclaringClass());
}
bf.destroySingletons();
}
use of org.springframework.beans.factory.UnsatisfiedDependencyException in project spring-framework by spring-projects.
the class AutowiredAnnotationBeanPostProcessorTests method testMethodInjectionWithMapAndMultipleMatches.
@Test
public void testMethodInjectionWithMapAndMultipleMatches() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
bpp.setBeanFactory(bf);
bf.addBeanPostProcessor(bpp);
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(MapMethodInjectionBean.class));
bf.registerBeanDefinition("testBean1", new RootBeanDefinition(TestBean.class));
bf.registerBeanDefinition("testBean2", new RootBeanDefinition(TestBean.class));
try {
bf.getBean("annotatedBean");
fail("should have failed, more than one bean of type");
} catch (UnsatisfiedDependencyException ex) {
// expected
assertSame(MapMethodInjectionBean.class, ex.getInjectionPoint().getMethodParameter().getDeclaringClass());
}
bf.destroySingletons();
}
use of org.springframework.beans.factory.UnsatisfiedDependencyException in project spring-framework by spring-projects.
the class AutowiredAnnotationBeanPostProcessorTests method testCustomAnnotationOptionalFieldResourceInjectionWhenMultipleDependenciesFound.
@Test
public void testCustomAnnotationOptionalFieldResourceInjectionWhenMultipleDependenciesFound() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
bpp.setAutowiredAnnotationType(MyAutowired.class);
bpp.setRequiredParameterName("optional");
bpp.setRequiredParameterValue(false);
bpp.setBeanFactory(bf);
bf.addBeanPostProcessor(bpp);
bf.registerBeanDefinition("customBean", new RootBeanDefinition(CustomAnnotationOptionalFieldResourceInjectionBean.class));
TestBean tb1 = new TestBean();
bf.registerSingleton("testBean1", tb1);
TestBean tb2 = new TestBean();
bf.registerSingleton("testBean2", tb2);
try {
bf.getBean("customBean");
fail("Should have thrown UnsatisfiedDependencyException");
} catch (UnsatisfiedDependencyException ex) {
// expected
assertSame(CustomAnnotationOptionalFieldResourceInjectionBean.class, ex.getInjectionPoint().getField().getDeclaringClass());
}
bf.destroySingletons();
}
Aggregations