List of usage examples for org.springframework.beans.factory UnsatisfiedDependencyException getMessage
@Override
@Nullable
public String getMessage()
From source file:org.springframework.beans.factory.DefaultListableBeanFactoryTests.java
@Test public void testAutowireWithTwoMatchesForConstructorDependency() { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); RootBeanDefinition bd = new RootBeanDefinition(TestBean.class); lbf.registerBeanDefinition("rod", bd); RootBeanDefinition bd2 = new RootBeanDefinition(TestBean.class); lbf.registerBeanDefinition("rod2", bd2); try {/*from w w w .ja v a2 s .co m*/ lbf.autowire(ConstructorDependency.class, AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, false); fail("Should have thrown UnsatisfiedDependencyException"); } catch (UnsatisfiedDependencyException ex) { // expected assertTrue(ex.getMessage().contains("rod")); assertTrue(ex.getMessage().contains("rod2")); } }
From source file:org.springframework.beans.factory.DefaultListableBeanFactoryTests.java
@Test public void testAutowireBeanByTypeWithTwoMatches() { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); RootBeanDefinition bd = new RootBeanDefinition(TestBean.class); RootBeanDefinition bd2 = new RootBeanDefinition(TestBean.class); lbf.registerBeanDefinition("test", bd); lbf.registerBeanDefinition("spouse", bd2); try {/* w ww .j a v a2 s .c o m*/ lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true); fail("Should have thrown UnsatisfiedDependencyException"); } catch (UnsatisfiedDependencyException ex) { // expected assertTrue(ex.getMessage().contains("test")); assertTrue(ex.getMessage().contains("spouse")); } }
From source file:org.springframework.beans.factory.DefaultListableBeanFactoryTests.java
@Test public void testAutowireBeanByTypeWithIdenticalPriorityCandidates() { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); lbf.setDependencyComparator(AnnotationAwareOrderComparator.INSTANCE); RootBeanDefinition bd = new RootBeanDefinition(HighPriorityTestBean.class); RootBeanDefinition bd2 = new RootBeanDefinition(HighPriorityTestBean.class); lbf.registerBeanDefinition("test", bd); lbf.registerBeanDefinition("spouse", bd2); try {//from w w w . jav a 2 s .c om lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true); fail("Should have thrown UnsatisfiedDependencyException"); } catch (UnsatisfiedDependencyException ex) { // expected assertNotNull("Exception should have cause", ex.getCause()); assertEquals("Wrong cause type", NoUniqueBeanDefinitionException.class, ex.getCause().getClass()); assertTrue(ex.getMessage().contains("5")); // conflicting priority } }