List of usage examples for org.springframework.beans.factory BeanCreationException getCause
public synchronized Throwable getCause()
From source file:com.revolsys.gis.tools.ProcessorPipelineTool.java
private static Throwable getBeanExceptionCause(final BeanCreationException e) { Throwable cause = e.getCause(); while (cause instanceof BeanCreationException || cause instanceof MethodInvocationException || cause instanceof PropertyAccessException) { final Throwable newCause = cause.getCause(); if (newCause != null) { cause = newCause;/*from w w w .j a v a 2 s .c o m*/ } } return cause; }
From source file:com.capgemini.archaius.spring.SpringPropertiesMissingFileIsNotOKTest.java
@Test public void missingSpringPropertiesFilesIsNotOkIfIgnoreResourceNotFoundPropertySetToFalse() { try {// w ww.jav a 2 s. c o m new ClassPathXmlApplicationContext("spring/springPropertiesMissingFileIsNotOKTest.xml"); fail("An exception should have been thrown when loading the context because the class path resource [META-INF/file-not-there.properties] cannot be resolved to a URL because it does not exist"); } catch (BeanCreationException ex) { assertThat(ex.getCause().getMessage(), is(equalTo( "Failed properties: Property 'locations' threw exception; nested exception is java.lang.RuntimeException: Problem setting the locations."))); } }
From source file:com.weasel.elasticsearch.test.xml.ElasticsearchMappingMergeFailedTest.java
@Test(expected = BeanCreationException.class) public void test_transport_client() { try {//from ww w . j ava2 s . c o m new ClassPathXmlApplicationContext( "fr/pilato/spring/elasticsearch/xml/es-mapping-failed-test-context.xml"); } catch (BeanCreationException e) { assertEquals(MergeMappingException.class, e.getCause().getClass()); throw e; } }
From source file:fr.pilato.spring.elasticsearch.it.xml.MappingFailedTest.java
@Test(expected = BeanCreationException.class) public void test_transport_client() { try {/*from www. j a v a 2 s . c om*/ new ClassPathXmlApplicationContext("models/mapping-failed/mapping-failed-context.xml"); } catch (BeanCreationException e) { assertEquals(IllegalArgumentException.class, e.getCause().getClass()); throw e; } }
From source file:fr.pilato.spring.elasticsearch.it.xml.SettingsFailedTest.java
@Test(expected = BeanCreationException.class) public void test_merge_settings_failure() { try {//from ww w .j a va2s .c o m new ClassPathXmlApplicationContext("models/settings-failed/settings-failed-context.xml"); } catch (BeanCreationException e) { assertEquals(IllegalArgumentException.class, e.getCause().getClass()); throw e; } }
From source file:com.weasel.elasticsearch.test.xml.ElasticsearchSettingsMergeFailedTest.java
@Test(expected = BeanCreationException.class) public void test_merge_settings_failure() { try {//from ww w . ja v a 2s . c om new ClassPathXmlApplicationContext( "fr/pilato/spring/elasticsearch/xml/es-settings-failed-test-context.xml"); } catch (BeanCreationException e) { assertEquals(ElasticSearchIllegalArgumentException.class, e.getCause().getClass()); throw e; } }
From source file:com.cloudera.cli.validator.Main.java
/** * From the arguments, run the validation. * * @param args command line arguments// w w w. j a v a2s . c om * @throws IOException anything goes wrong with streams. * @return exit code */ public int run(String[] args) throws IOException { Writer writer = new OutputStreamWriter(outStream, Constants.CHARSET_UTF_8); AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); try { BeanDefinition cmdOptsbeanDefinition = BeanDefinitionBuilder .rootBeanDefinition(CommandLineOptions.class).addConstructorArgValue(appName) .addConstructorArgValue(args).getBeanDefinition(); ctx.registerBeanDefinition(CommandLineOptions.BEAN_NAME, cmdOptsbeanDefinition); ctx.register(ApplicationConfiguration.class); ctx.refresh(); CommandLineOptions cmdOptions = ctx.getBean(CommandLineOptions.BEAN_NAME, CommandLineOptions.class); CommandLineOptions.Mode mode = cmdOptions.getMode(); if (mode == null) { throw new ParseException("No valid command line arguments"); } ValidationRunner runner = ctx.getBean(mode.runnerName, ValidationRunner.class); boolean success = runner.run(cmdOptions.getCommandLineOptionActiveTarget(), writer); if (success) { writer.write("Validation succeeded.\n"); } return success ? 0 : -1; } catch (BeanCreationException e) { String cause = e.getMessage(); if (e.getCause() instanceof BeanInstantiationException) { BeanInstantiationException bie = (BeanInstantiationException) e.getCause(); cause = bie.getMessage(); if (bie.getCause() != null) { cause = bie.getCause().getMessage(); } } IOUtils.write(cause + "\n", errStream); CommandLineOptions.printUsageMessage(appName, errStream); return -2; } catch (ParseException e) { LOG.debug("Exception", e); IOUtils.write(e.getMessage() + "\n", errStream); CommandLineOptions.printUsageMessage(appName, errStream); return -2; } finally { if (ctx != null) { ctx.close(); } writer.close(); } }
From source file:com.googlecode.ehcache.annotations.integration.ConfigurationFailureTest.java
/** * Test verifies behavior when no {@link Ehcache} is defined for * the cacheName attribute on the {@link Cacheable} annotated method AND * 'createMissingCaches' is false.//ww w.j av a2 s .c o m */ @Test public void testNoCache() { try { new ClassPathXmlApplicationContext("/noCacheTestContext.xml"); Assert.fail("Test should have failed with no Cache defined"); } catch (BeanCreationException bce) { Assert.assertEquals("missingCacheNameImpl", bce.getBeanName()); final CacheNotFoundException cnfe = (CacheNotFoundException) bce.getCause(); Assert.assertEquals("nonexistent", cnfe.getCacheName()); } }
From source file:ru.apertum.qsystem.server.Spring.java
private Spring() { try {// w w w . j a v a2 s . c o m factory = new ClassPathXmlApplicationContext("/ru/apertum/qsystem/spring/qsContext.xml"); } catch (BeanCreationException ex) { throw new ServerException( " ?? ??- ? ?: \"" + ex.getCause().getMessage() + "\"\n" + " ? \"" + ex.getBeanName() + "\"" + " : \"" + ex.getCause().getMessage() + "\"\n" + ex); } catch (BeansException ex) { throw new ServerException( " ??- ? ?: \"" + ex.getCause().getMessage() + "\"\n" + " : \"" + ex.getCause().getMessage() + "\"\n" + ex); } catch (Exception ex) { throw new ServerException( " ?? ? ?: " + ex); } //sessionFactory = factory.getBean("mySessionFactory", SessionFactoryImpl.class); //ht = new HibernateTemplate(sessionFactory); final ComboPooledDataSource bds = (ComboPooledDataSource) factory.getBean("c3p0DataSource"); driverClassName = bds.getDriverClass(); url = bds.getJdbcUrl(); username = bds.getUser(); password = bds.getPassword(); }
From source file:org.jasypt.spring31.annotation.EncryptablePropertySourcePostProcessorTest.java
@Test public void withUnresolvablePlaceholder() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.register(ConfigWithUnresolvablePlaceholder.class); try {//from w ww. j a va 2 s . co m ctx.refresh(); } catch (BeanCreationException ex) { assertTrue(ex.getCause() instanceof IllegalArgumentException); } ctx.close(); }