private String determineDescription(BeanCreationException ex) { if (StringUtils.hasText(ex.getResourceDescription())) { return String.format(" defined in %s", ex.getResourceDescription()); } InjectionPoint failedInjectionPoint = findFailedInjectionPoint(ex); if (failedInjectionPoint != null && failedInjectionPoint.getField() != null) { return String.format(" (field %s)", failedInjectionPoint.getField()); } return ""; }
/** * Test that if a custom initializer throws an exception, it's handled correctly */ @Test public void testInitMethodThrowsException() { DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(INITIALIZERS_CONTEXT); try { xbf.getBean("init-method2"); fail(); } catch (BeanCreationException ex) { assertTrue(ex.getResourceDescription().contains("initializers.xml")); assertEquals("init-method2", ex.getBeanName()); assertTrue(ex.getCause() instanceof IOException); } }