Java Code Examples for org.springframework.beans.factory.BeanCreationException#getCause()
The following examples show how to use
org.springframework.beans.factory.BeanCreationException#getCause() .
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: BeanExceptionMapper.java From crnk-framework with Apache License 2.0 | 6 votes |
@Override public ErrorResponse toErrorResponse(BeanCreationException exception) { Throwable cause = exception.getCause(); while (cause instanceof BeanCreationException || cause instanceof BeanInstantiationException) { cause = cause.getCause(); } if (cause != null) { Optional<ExceptionMapper> mapper = context.getExceptionMapperRegistry().findMapperFor(cause.getClass()); if (mapper.isPresent()) { return mapper.get().toErrorResponse(cause); } } LOGGER.error("failed to setup spring beans", exception); // no mapper found, return default error int status = HttpStatus.INTERNAL_SERVER_ERROR_500; ErrorData errorData = ErrorData.builder().setStatus(Integer.toString(status)) .setTitle(exception.getMessage()).build(); return ErrorResponse.builder().setSingleErrorData(errorData).setStatus(status).build(); }
Example 2
Source File: BeanDefinitionTest.java From breeze with Apache License 2.0 | 6 votes |
@Test public void brokenWithUnboundBolt() throws Exception { beansXml = "<breeze:topology id='t1'>" + "<breeze:spout id='s1' beanType='eu.icolumbo.breeze.TestBean' signature='ping()' outputFields='feed'/>" + "<breeze:bolt id='b1' beanType='eu.icolumbo.breeze.TestBean' signature='echo(other)'/>" + "</breeze:topology>"; refresh(); try { getBean(StormTopology.class); fail("no exception"); } catch (BeanCreationException e) { Throwable cause = e.getCause(); assertNotNull("cause", cause); String expected = "Can't resolve all input fields for: [[bolt 'b1']]"; assertEquals(expected, cause.getMessage()); } }
Example 3
Source File: ProxyFactoryBeanTests.java From spring-analysis-note with MIT License | 5 votes |
private void testDoubleTargetSourceIsRejected(String name) { try { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(DBL_TARGETSOURCE_CONTEXT, CLASS)); bf.getBean(name); fail("Should not allow TargetSource to be specified in interceptorNames as well as targetSource property"); } catch (BeanCreationException ex) { // Root cause of the problem must be an AOP exception AopConfigException aex = (AopConfigException) ex.getCause(); assertTrue(aex.getMessage().contains("TargetSource")); } }
Example 4
Source File: ProxyFactoryBeanTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testTargetSourceNotAtEndOfInterceptorNamesIsRejected() { try { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(NOTLAST_TARGETSOURCE_CONTEXT, CLASS)); bf.getBean("targetSourceNotLast"); fail("TargetSource or non-advised object must be last in interceptorNames"); } catch (BeanCreationException ex) { // Root cause of the problem must be an AOP exception AopConfigException aex = (AopConfigException) ex.getCause(); assertTrue(aex.getMessage().contains("interceptorNames")); } }
Example 5
Source File: AbstractBeanFactoryTests.java From spring-analysis-note with MIT License | 5 votes |
public void xtestTypeMismatch() { try { getBeanFactory().getBean("typeMismatch"); fail("Shouldn't succeed with type mismatch"); } catch (BeanCreationException wex) { assertEquals("typeMismatch", wex.getBeanName()); assertTrue(wex.getCause() instanceof PropertyBatchUpdateException); PropertyBatchUpdateException ex = (PropertyBatchUpdateException) wex.getCause(); // Further tests assertTrue("Has one error ", ex.getExceptionCount() == 1); assertTrue("Error is for field age", ex.getPropertyAccessException("age") != null); assertTrue("We have rejected age in exception", ex.getPropertyAccessException("age").getPropertyChangeEvent().getNewValue().equals("34x")); } }
Example 6
Source File: ProxyFactoryBeanTests.java From java-technology-stack with MIT License | 5 votes |
private void testDoubleTargetSourceIsRejected(String name) { try { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(DBL_TARGETSOURCE_CONTEXT, CLASS)); bf.getBean(name); fail("Should not allow TargetSource to be specified in interceptorNames as well as targetSource property"); } catch (BeanCreationException ex) { // Root cause of the problem must be an AOP exception AopConfigException aex = (AopConfigException) ex.getCause(); assertTrue(aex.getMessage().contains("TargetSource")); } }
Example 7
Source File: ProxyFactoryBeanTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testTargetSourceNotAtEndOfInterceptorNamesIsRejected() { try { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(NOTLAST_TARGETSOURCE_CONTEXT, CLASS)); bf.getBean("targetSourceNotLast"); fail("TargetSource or non-advised object must be last in interceptorNames"); } catch (BeanCreationException ex) { // Root cause of the problem must be an AOP exception AopConfigException aex = (AopConfigException) ex.getCause(); assertTrue(aex.getMessage().contains("interceptorNames")); } }
Example 8
Source File: AbstractBeanFactoryTests.java From java-technology-stack with MIT License | 5 votes |
public void xtestTypeMismatch() { try { getBeanFactory().getBean("typeMismatch"); fail("Shouldn't succeed with type mismatch"); } catch (BeanCreationException wex) { assertEquals("typeMismatch", wex.getBeanName()); assertTrue(wex.getCause() instanceof PropertyBatchUpdateException); PropertyBatchUpdateException ex = (PropertyBatchUpdateException) wex.getCause(); // Further tests assertTrue("Has one error ", ex.getExceptionCount() == 1); assertTrue("Error is for field age", ex.getPropertyAccessException("age") != null); assertTrue("We have rejected age in exception", ex.getPropertyAccessException("age").getPropertyChangeEvent().getNewValue().equals("34x")); } }
Example 9
Source File: ProxyFactoryBeanTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
private void testDoubleTargetSourceIsRejected(String name) { try { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(DBL_TARGETSOURCE_CONTEXT, CLASS)); bf.getBean(name); fail("Should not allow TargetSource to be specified in interceptorNames as well as targetSource property"); } catch (BeanCreationException ex) { // Root cause of the problem must be an AOP exception AopConfigException aex = (AopConfigException) ex.getCause(); assertTrue(aex.getMessage().indexOf("TargetSource") != -1); } }
Example 10
Source File: ProxyFactoryBeanTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testTargetSourceNotAtEndOfInterceptorNamesIsRejected() { try { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(NOTLAST_TARGETSOURCE_CONTEXT, CLASS)); bf.getBean("targetSourceNotLast"); fail("TargetSource or non-advised object must be last in interceptorNames"); } catch (BeanCreationException ex) { // Root cause of the problem must be an AOP exception AopConfigException aex = (AopConfigException) ex.getCause(); assertTrue(aex.getMessage().indexOf("interceptorNames") != -1); } }
Example 11
Source File: AbstractBeanFactoryTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
public void xtestTypeMismatch() { try { getBeanFactory().getBean("typeMismatch"); fail("Shouldn't succeed with type mismatch"); } catch (BeanCreationException wex) { assertEquals("typeMismatch", wex.getBeanName()); assertTrue(wex.getCause() instanceof PropertyBatchUpdateException); PropertyBatchUpdateException ex = (PropertyBatchUpdateException) wex.getCause(); // Further tests assertTrue("Has one error ", ex.getExceptionCount() == 1); assertTrue("Error is for field age", ex.getPropertyAccessException("age") != null); assertTrue("We have rejected age in exception", ex.getPropertyAccessException("age").getPropertyChangeEvent().getNewValue().equals("34x")); } }
Example 12
Source File: AmqpContextConfigTest.java From sinavi-jfw with Apache License 2.0 | 5 votes |
@Test public void ポート番号が不正な場合は例外がスローされる() throws Throwable { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("ポート番号は数字で入力してください。"); try { new AnnotationConfigApplicationContext(InvalidProperties.class); fail(); } catch (BeanCreationException e) { throw e.getCause(); } }
Example 13
Source File: BaseLdapPathBeanPostprocessorITest.java From spring-ldap with Apache License 2.0 | 5 votes |
@Test public void testPostProcessBeforeInitializationMultipleContextSources() throws Exception { try { new ClassPathXmlApplicationContext("/conf/baseLdapPathPostProcessorMultiContextSourceTestContext.xml"); fail("BeanCreationException expected"); } catch (BeanCreationException expected) { Throwable cause = expected.getCause(); assertThat(cause instanceof NoSuchBeanDefinitionException).isTrue(); } }
Example 14
Source File: BaseLdapPathBeanPostprocessorITest.java From spring-ldap with Apache License 2.0 | 5 votes |
@Test public void testPostProcessBeforeInitializationNoContextSource() throws Exception { try { new ClassPathXmlApplicationContext("/conf/baseLdapPathPostProcessorNoContextSourceTestContext.xml"); fail("BeanCreationException expected"); } catch (BeanCreationException expected) { Throwable cause = expected.getCause(); assertThat(cause instanceof NoSuchBeanDefinitionException).isTrue(); } }