Java Code Examples for org.springframework.beans.factory.BeanCreationException#getRootCause()
The following examples show how to use
org.springframework.beans.factory.BeanCreationException#getRootCause() .
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: DataFlowServerConfigurationTests.java From spring-cloud-dataflow with Apache License 2.0 | 6 votes |
/** * Verify that embedded h2 does not start if h2 url is specified with with the * spring.dataflow.embedded.database.enabled is set to false. * * @throws Throwable if any error occurs and should be handled by the caller. */ @Test(expected = ConnectException.class) public void testDoNotStartEmbeddedH2Server() throws Throwable { Throwable exceptionResult = null; Map<String, Object> myMap = new HashMap<>(); myMap.put("spring.datasource.url", "jdbc:h2:tcp://localhost:19092/mem:dataflow"); myMap.put("spring.dataflow.embedded.database.enabled", "false"); myMap.put("spring.jpa.database", "H2"); propertySources.addFirst(new MapPropertySource("EnvironmentTestPropsource", myMap)); context.setEnvironment(environment); try { context.refresh(); } catch (BeanCreationException exception) { exceptionResult = exception.getRootCause(); } assertNotNull(exceptionResult); throw exceptionResult; }
Example 2
Source File: OverloadedAdviceTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testExceptionOnConfigParsingWithAmbiguousAdviceMethod() { try { new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-ambiguous.xml", getClass()); } catch (BeanCreationException ex) { Throwable cause = ex.getRootCause(); assertTrue("Should be IllegalArgumentException", cause instanceof IllegalArgumentException); assertTrue("Cannot resolve method 'myBeforeAdvice' to a unique method", cause.getMessage().contains("Cannot resolve method 'myBeforeAdvice' to a unique method")); } }
Example 3
Source File: OverloadedAdviceTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testExceptionOnConfigParsingWithAmbiguousAdviceMethod() { try { new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-ambiguous.xml", getClass()); } catch (BeanCreationException ex) { Throwable cause = ex.getRootCause(); assertTrue("Should be IllegalArgumentException", cause instanceof IllegalArgumentException); assertTrue("Cannot resolve method 'myBeforeAdvice' to a unique method", cause.getMessage().indexOf("Cannot resolve method 'myBeforeAdvice' to a unique method") != -1); } }
Example 4
Source File: OverloadedAdviceTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testExceptionOnConfigParsingWithMismatchedAdviceMethod() { try { new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass()); } catch (BeanCreationException ex) { Throwable cause = ex.getRootCause(); assertTrue("Should be IllegalArgumentException", cause instanceof IllegalArgumentException); assertTrue("invalidAbsoluteTypeName should be detected by AJ", cause.getMessage().indexOf("invalidAbsoluteTypeName") != -1); } }
Example 5
Source File: EnableCachingTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test(expected = IllegalStateException.class) public void noCacheManagerBeans() throws Throwable { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.register(EmptyConfig.class); try { ctx.refresh(); } catch (BeanCreationException ex) { Throwable root = ex.getRootCause(); assertTrue(root.getMessage().contains("No bean of type CacheManager")); throw root; } }
Example 6
Source File: EnableCachingTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test(expected = IllegalStateException.class) public void multipleCachingConfigurers() throws Throwable { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.register(MultiCacheManagerConfigurer.class, EnableCachingConfig.class); try { ctx.refresh(); } catch (BeanCreationException ex) { Throwable root = ex.getRootCause(); assertTrue(root.getMessage().contains("implementations of CachingConfigurer")); throw root; } }
Example 7
Source File: EnableCachingTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test(expected = IllegalStateException.class) public void multipleCacheManagerBeans() throws Throwable { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.register(MultiCacheManagerConfig.class); try { ctx.refresh(); } catch (BeanCreationException ex) { Throwable root = ex.getRootCause(); assertTrue(root.getMessage().contains("beans of type CacheManager")); throw root; } }
Example 8
Source File: AspectJEnableCachingIsolatedTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void multipleCachingConfigurers() { try { load(MultiCacheManagerConfigurer.class, EnableCachingConfig.class); } catch (BeanCreationException ex) { Throwable root = ex.getRootCause(); assertTrue(root instanceof IllegalStateException); assertTrue(ex.getMessage().contains("implementations of CachingConfigurer")); } }
Example 9
Source File: OverloadedAdviceTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testExceptionOnConfigParsingWithMismatchedAdviceMethod() { try { new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass()); } catch (BeanCreationException ex) { Throwable cause = ex.getRootCause(); assertTrue("Should be IllegalArgumentException", cause instanceof IllegalArgumentException); assertTrue("invalidAbsoluteTypeName should be detected by AJ", cause.getMessage().contains("invalidAbsoluteTypeName")); } }
Example 10
Source File: EnableCachingTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void multipleCachingConfigurers() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.register(MultiCacheManagerConfigurer.class, EnableCachingConfig.class); try { ctx.refresh(); } catch (BeanCreationException ex) { Throwable root = ex.getRootCause(); assertTrue(root instanceof IllegalStateException); assertTrue(root.getMessage().contains("implementations of CachingConfigurer")); } }
Example 11
Source File: AspectJEnableCachingIsolatedTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void multipleCachingConfigurers() { try { load(MultiCacheManagerConfigurer.class, EnableCachingConfig.class); } catch (BeanCreationException ex) { Throwable root = ex.getRootCause(); assertTrue(root instanceof IllegalStateException); assertTrue(ex.getMessage().contains("implementations of CachingConfigurer")); } }
Example 12
Source File: OverloadedAdviceTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testExceptionOnConfigParsingWithAmbiguousAdviceMethod() { try { new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-ambiguous.xml", getClass()); } catch (BeanCreationException ex) { Throwable cause = ex.getRootCause(); assertTrue("Should be IllegalArgumentException", cause instanceof IllegalArgumentException); assertTrue("Cannot resolve method 'myBeforeAdvice' to a unique method", cause.getMessage().contains("Cannot resolve method 'myBeforeAdvice' to a unique method")); } }
Example 13
Source File: OverloadedAdviceTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testExceptionOnConfigParsingWithMismatchedAdviceMethod() { try { new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass()); } catch (BeanCreationException ex) { Throwable cause = ex.getRootCause(); assertTrue("Should be IllegalArgumentException", cause instanceof IllegalArgumentException); assertTrue("invalidAbsoluteTypeName should be detected by AJ", cause.getMessage().contains("invalidAbsoluteTypeName")); } }
Example 14
Source File: EnableCachingTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void multipleCachingConfigurers() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.register(MultiCacheManagerConfigurer.class, EnableCachingConfig.class); try { ctx.refresh(); } catch (BeanCreationException ex) { Throwable root = ex.getRootCause(); assertTrue(root instanceof IllegalStateException); assertTrue(root.getMessage().contains("implementations of CachingConfigurer")); } }
Example 15
Source File: CommonAnnotationBeanPostProcessorTests.java From spring-analysis-note with MIT License | 4 votes |
@Test public void testExtendedResourceInjectionWithOverriding() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor(); bpp.setBeanFactory(bf); bf.addBeanPostProcessor(bpp); bf.registerResolvableDependency(BeanFactory.class, bf); PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer(); Properties props = new Properties(); props.setProperty("tb", "testBean3"); ppc.setProperties(props); ppc.postProcessBeanFactory(bf); RootBeanDefinition annotatedBd = new RootBeanDefinition(ExtendedResourceInjectionBean.class); TestBean tb5 = new TestBean(); annotatedBd.getPropertyValues().add("testBean2", tb5); bf.registerBeanDefinition("annotatedBean", annotatedBd); bf.registerBeanDefinition("annotatedBean2", new RootBeanDefinition(NamedResourceInjectionBean.class)); TestBean tb = new TestBean(); bf.registerSingleton("testBean", tb); TestBean tb2 = new TestBean(); bf.registerSingleton("testBean2", tb2); TestBean tb3 = new TestBean(); bf.registerSingleton("testBean3", tb3); TestBean tb4 = new TestBean(); bf.registerSingleton("testBean4", tb4); NestedTestBean tb6 = new NestedTestBean(); bf.registerSingleton("xy", tb6); ExtendedResourceInjectionBean bean = (ExtendedResourceInjectionBean) bf.getBean("annotatedBean"); assertTrue(bean.initCalled); assertTrue(bean.init2Called); assertSame(tb, bean.getTestBean()); assertSame(tb5, bean.getTestBean2()); assertSame(tb4, bean.getTestBean3()); assertSame(tb3, bean.getTestBean4()); assertSame(tb6, bean.testBean5); assertSame(tb6, bean.testBean6); assertSame(bf, bean.beanFactory); try { bf.getBean("annotatedBean2"); } catch (BeanCreationException ex) { assertTrue(ex.getRootCause() instanceof NoSuchBeanDefinitionException); NoSuchBeanDefinitionException innerEx = (NoSuchBeanDefinitionException) ex.getRootCause(); assertEquals("testBean9", innerEx.getBeanName()); } bf.destroySingletons(); assertTrue(bean.destroyCalled); assertTrue(bean.destroy2Called); }
Example 16
Source File: CommonAnnotationBeanPostProcessorTests.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Test public void testExtendedResourceInjectionWithOverriding() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor(); bpp.setBeanFactory(bf); bf.addBeanPostProcessor(bpp); bf.registerResolvableDependency(BeanFactory.class, bf); PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer(); Properties props = new Properties(); props.setProperty("tb", "testBean3"); ppc.setProperties(props); ppc.postProcessBeanFactory(bf); RootBeanDefinition annotatedBd = new RootBeanDefinition(ExtendedResourceInjectionBean.class); TestBean tb5 = new TestBean(); annotatedBd.getPropertyValues().add("testBean2", tb5); bf.registerBeanDefinition("annotatedBean", annotatedBd); bf.registerBeanDefinition("annotatedBean2", new RootBeanDefinition(NamedResourceInjectionBean.class)); TestBean tb = new TestBean(); bf.registerSingleton("testBean", tb); TestBean tb2 = new TestBean(); bf.registerSingleton("testBean2", tb2); TestBean tb3 = new TestBean(); bf.registerSingleton("testBean3", tb3); TestBean tb4 = new TestBean(); bf.registerSingleton("testBean4", tb4); NestedTestBean tb6 = new NestedTestBean(); bf.registerSingleton("xy", tb6); ExtendedResourceInjectionBean bean = (ExtendedResourceInjectionBean) bf.getBean("annotatedBean"); assertTrue(bean.initCalled); assertTrue(bean.init2Called); assertSame(tb, bean.getTestBean()); assertSame(tb5, bean.getTestBean2()); assertSame(tb4, bean.getTestBean3()); assertSame(tb3, bean.getTestBean4()); assertSame(tb6, bean.testBean5); assertSame(tb6, bean.testBean6); assertSame(bf, bean.beanFactory); try { bf.getBean("annotatedBean2"); } catch (BeanCreationException ex) { assertTrue(ex.getRootCause() instanceof NoSuchBeanDefinitionException); NoSuchBeanDefinitionException innerEx = (NoSuchBeanDefinitionException) ex.getRootCause(); assertEquals("testBean9", innerEx.getBeanName()); } bf.destroySingletons(); assertTrue(bean.destroyCalled); assertTrue(bean.destroy2Called); }
Example 17
Source File: CommonAnnotationBeanPostProcessorTests.java From java-technology-stack with MIT License | 4 votes |
@Test public void testExtendedResourceInjectionWithOverriding() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor(); bpp.setBeanFactory(bf); bf.addBeanPostProcessor(bpp); bf.registerResolvableDependency(BeanFactory.class, bf); PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer(); Properties props = new Properties(); props.setProperty("tb", "testBean3"); ppc.setProperties(props); ppc.postProcessBeanFactory(bf); RootBeanDefinition annotatedBd = new RootBeanDefinition(ExtendedResourceInjectionBean.class); TestBean tb5 = new TestBean(); annotatedBd.getPropertyValues().add("testBean2", tb5); bf.registerBeanDefinition("annotatedBean", annotatedBd); bf.registerBeanDefinition("annotatedBean2", new RootBeanDefinition(NamedResourceInjectionBean.class)); TestBean tb = new TestBean(); bf.registerSingleton("testBean", tb); TestBean tb2 = new TestBean(); bf.registerSingleton("testBean2", tb2); TestBean tb3 = new TestBean(); bf.registerSingleton("testBean3", tb3); TestBean tb4 = new TestBean(); bf.registerSingleton("testBean4", tb4); NestedTestBean tb6 = new NestedTestBean(); bf.registerSingleton("xy", tb6); ExtendedResourceInjectionBean bean = (ExtendedResourceInjectionBean) bf.getBean("annotatedBean"); assertTrue(bean.initCalled); assertTrue(bean.init2Called); assertSame(tb, bean.getTestBean()); assertSame(tb5, bean.getTestBean2()); assertSame(tb4, bean.getTestBean3()); assertSame(tb3, bean.getTestBean4()); assertSame(tb6, bean.testBean5); assertSame(tb6, bean.testBean6); assertSame(bf, bean.beanFactory); try { bf.getBean("annotatedBean2"); } catch (BeanCreationException ex) { assertTrue(ex.getRootCause() instanceof NoSuchBeanDefinitionException); NoSuchBeanDefinitionException innerEx = (NoSuchBeanDefinitionException) ex.getRootCause(); assertEquals("testBean9", innerEx.getBeanName()); } bf.destroySingletons(); assertTrue(bean.destroyCalled); assertTrue(bean.destroy2Called); }