Throwable rootCause = ex.getMostSpecificCause(); if (rootCause instanceof BeanCurrentlyInCreationException) { BeanCreationException bce = (BeanCreationException) rootCause;
Throwable rootCause = ex.getMostSpecificCause(); if (rootCause instanceof BeanCurrentlyInCreationException) { BeanCreationException bce = (BeanCreationException) rootCause;
Throwable rootCause = ex.getMostSpecificCause(); if (rootCause instanceof BeanCurrentlyInCreationException) { BeanCreationException bce = (BeanCreationException) rootCause;
((BeanCreationException) ex).getMostSpecificCause() instanceof BeanCurrentlyInCreationException) { if (logger.isTraceEnabled()) { logger.trace("Could not determine scripted object type for bean '" + beanName + "': " +
((BeanCreationException) ex).getMostSpecificCause() instanceof BeanCurrentlyInCreationException) { if (logger.isTraceEnabled()) { logger.trace("Could not determine scripted object type for bean '" + beanName + "': " +
Throwable rootCause = ex.getMostSpecificCause(); if (rootCause instanceof BeanCurrentlyInCreationException) { BeanCreationException bce = (BeanCreationException) rootCause;
Throwable rootCause = ex.getMostSpecificCause(); if (rootCause instanceof BeanCurrentlyInCreationException) { BeanCreationException bce = (BeanCreationException) rootCause;
Throwable rootCause = ex.getMostSpecificCause(); if (rootCause instanceof BeanCurrentlyInCreationException) { BeanCreationException bce = (BeanCreationException) rootCause;
@Test public void testConstructor() throws Exception { try { beanFactory.getBean("constructor"); fail("expected security exception"); } catch (BeanCreationException ex) { // expected assertTrue(ex.getMostSpecificCause() instanceof SecurityException); } }
@Test public void testTrustedFactoryMethod() throws Exception { try { beanFactory.getBean("privileged-static-factory-method"); fail("expected security exception"); } catch (BeanCreationException ex) { assertTrue(ex.getMostSpecificCause() instanceof SecurityException); } }
@Test public void testCustomStaticFactoryMethod() throws Exception { try { beanFactory.getBean("custom-static-factory-method"); fail("expected security exception"); } catch (BeanCreationException ex) { assertTrue(ex.getMostSpecificCause() instanceof SecurityException); } }
@Test public void testCustomInstanceFactoryMethod() throws Exception { try { beanFactory.getBean("custom-factory-method"); fail("expected security exception"); } catch (BeanCreationException ex) { assertTrue(ex.getMostSpecificCause() instanceof SecurityException); } }
Throwable rootCause = ex.getMostSpecificCause(); if (rootCause instanceof BeanCurrentlyInCreationException) { BeanCreationException bce = (BeanCreationException) rootCause;
@Test public void testNonLenientDependencyMatchingFactoryMethod() { DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONSTRUCTOR_ARG_CONTEXT); AbstractBeanDefinition bd = (AbstractBeanDefinition) xbf.getBeanDefinition("lenientDependencyTestBeanFactoryMethod"); bd.setLenientConstructorResolution(false); try { xbf.getBean("lenientDependencyTestBeanFactoryMethod"); fail("Should have thrown BeanCreationException"); } catch (BeanCreationException ex) { // expected ex.printStackTrace(); assertTrue(ex.getMostSpecificCause().getMessage().contains("Ambiguous")); } }
@Test public void testNonLenientDependencyMatching() { DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONSTRUCTOR_ARG_CONTEXT); AbstractBeanDefinition bd = (AbstractBeanDefinition) xbf.getBeanDefinition("lenientDependencyTestBean"); bd.setLenientConstructorResolution(false); try { xbf.getBean("lenientDependencyTestBean"); fail("Should have thrown BeanCreationException"); } catch (BeanCreationException ex) { // expected ex.printStackTrace(); assertTrue(ex.getMostSpecificCause().getMessage().contains("Ambiguous")); } }
@Test public void testAutowireCandidatePatternDoesNotMatch() { GenericApplicationContext context = new GenericApplicationContext(); ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context); scanner.setIncludeAnnotationConfig(true); scanner.setBeanNameGenerator(new TestBeanNameGenerator()); scanner.setAutowireCandidatePatterns("*NoSuchDao"); scanner.scan(BASE_PACKAGE); try { context.refresh(); context.getBean("fooService"); fail("BeanCreationException expected; fooDao should not have been an autowire-candidate"); } catch (BeanCreationException expected) { assertTrue(expected.getMostSpecificCause() instanceof NoSuchBeanDefinitionException); } }
public <T> Map<String, T> getBeansOfType(Class<T> type, boolean includeNonSingletons, boolean allowEagerInit) throws BeansException { String[] beanNames = getBeanNamesForType(type, includeNonSingletons, allowEagerInit); Map<String, T> result = new LinkedHashMap<String, T>(beanNames.length); for (String beanName : beanNames) { try { result.put(beanName, getBean(beanName, type)); } catch (BeanCreationException ex) { Throwable rootCause = ex.getMostSpecificCause(); if (rootCause instanceof BeanCurrentlyInCreationException) { BeanCreationException bce = (BeanCreationException) rootCause; if (isCurrentlyInCreation(bce.getBeanName())) { if (this.logger.isDebugEnabled()) { this.logger.debug("Ignoring match to currently created bean '" + beanName + "': " + ex.getMessage()); } onSuppressedException(ex); // Ignore: indicates a circular reference when autowiring constructors. // We want to find matches other than the currently created bean itself. continue; } } throw ex; } } return result; }
@Test(expected = IllegalArgumentException.class) public void delimitersNotAllowedWithExpression() throws Throwable { try { new ClassPathXmlApplicationContext("SplitterIntegrationTests-invalidExpression.xml", SplitterIntegrationTests.class).close(); } catch (BeanCreationException e) { Throwable cause = e.getMostSpecificCause(); assertNotNull(cause); assertTrue(cause instanceof IllegalArgumentException); assertTrue(cause.getMessage().contains("'delimiters' property is only available")); throw cause; } }
@Test(expected = IllegalArgumentException.class) public void delimitersNotAllowedWithRef() throws Throwable { try { new ClassPathXmlApplicationContext("SplitterIntegrationTests-invalidRef.xml", SplitterIntegrationTests.class).close(); } catch (BeanCreationException e) { Throwable cause = e.getMostSpecificCause(); assertNotNull(cause); assertTrue(cause instanceof IllegalArgumentException); assertTrue(cause.getMessage().contains("'delimiters' property is only available")); throw cause; } }
@Test(expected = IllegalArgumentException.class) public void delimitersNotAllowedWithInnerBean() throws Throwable { try { new ClassPathXmlApplicationContext("SplitterIntegrationTests-invalidInnerBean.xml", SplitterIntegrationTests.class).close(); } catch (BeanCreationException e) { Throwable cause = e.getMostSpecificCause(); assertNotNull(cause); assertTrue(cause instanceof IllegalArgumentException); assertTrue(cause.getMessage().contains("'delimiters' property is only available")); throw cause; } }