List of usage examples for org.springframework.beans.factory BeanCreationException getMessage
@Override
@Nullable
public String getMessage()
From source file:com.home.ln_spring.ch5.lifecycle.SimpleBean.java
private static SimpleBean getBean(String beanName, ApplicationContext ctx) { try {//from w ww. j av a 2s . c o m SimpleBean sb = (SimpleBean) ctx.getBean(beanName); System.out.println(sb); return sb; } catch (BeanCreationException ex) { System.out.println("An error occured in bean configuration1: " + ex.getMessage()); return null; } }
From source file:com.home.ln_spring.ch5.lifecycle.SimpleBeanWithInterface.java
private static SimpleBeanWithInterface getBean(String beanName, ApplicationContext ctx) { try {//from w ww. j ava 2s.c o m SimpleBeanWithInterface sb = (SimpleBeanWithInterface) ctx.getBean(beanName); System.out.println(sb); return sb; } catch (BeanCreationException ex) { System.out.println("An error occured in bean configuration1: " + ex.getMessage()); return null; } }
From source file:com.pactera.edg.am.metamanager.extractor.util.AdapterContextLoader.java
/** * //from www . j a va2s .c o m * SpringClassPathXMLApplicationContext,????${var} * prop??? ??.properties??,??${var} * * @param configLocations * application context? * @param props * ??application context????key/value * @return ApplicationContext Application * Context,?,??,bean,null * @exception */ public static ApplicationContext createApplicationContext(String[] configLocations, Properties props) { // :spring?system properties??. Properties bakProps = null; String logMsg = null; try { if (props != null && props.size() > 0) { // system properties bakProps = System.getProperties(); for (Object key : props.keySet()) { System.setProperty((String) key, props.getProperty((String) key)); } if (log.isDebugEnabled()) { StringBuffer sb = new StringBuffer(); sb.append("??springxml?${var}prop:\n"); for (Object key : props.keySet()) { sb.append(key + "=" + System.getProperty((String) key)); sb.append("\n"); } log.debug(sb.toString()); } } return new ClassPathXmlApplicationContext(configLocations); } catch (BeanDefinitionStoreException bse) { // logMsg = new StringBuilder("?spring,?") .append(Arrays.toString(configLocations)).append(bse.getMessage()).toString(); log.error(logMsg, bse); AdapterExtractorContext.addExtractorLog(ExtractorLogLevel.ERROR, logMsg); throw bse; } catch (BeanCreationException ce) { // BEAN,?RMI?? logMsg = new StringBuilder("?spring,?BEAN,") .append(Arrays.toString(configLocations)).append(ce.getMessage()).toString(); log.error(logMsg, ce); if (logMsg.indexOf("ORA-01017") > -1 || logMsg.indexOf("Invalid password") > -1) { // ORACLE???? AdapterExtractorContext.addExtractorLog(ExtractorLogLevel.ERROR, "??/?,?,???????!"); } else { AdapterExtractorContext.addExtractorLog(ExtractorLogLevel.ERROR, logMsg); } throw ce; } finally { // system properties,???,?? if (bakProps != null) { System.setProperties(bakProps); } } }
From source file:com.pactera.edg.am.metamanager.extractor.util.ExtractorContextLoader.java
/** * ??SPRING,,???/*from w w w. ja va 2 s. c om*/ * * @return * @throws SpringContextLoadException */ public static boolean initContext() throws SpringContextLoadException { try { if (aContext == null) { aContext = new ClassPathXmlApplicationContext( new String[] { Constants.EXTRACTOR_CONF_PATH, Constants.EXTRACTOR_RMI_CONF_PATH }); // JVM??,JVM,? aContext.registerShutdownHook(); // ? registerExtractorLogObservable(); } return true; } catch (BeanDefinitionStoreException bse) { // log.error(new StringBuilder("?spring,?") .append(Constants.EXTRACTOR_CONF_PATH).append(",").append(Constants.EXTRACTOR_RMI_CONF_PATH) .append(",").append(bse.getMessage()).toString()); if (log.isDebugEnabled()) { log.error(new StringBuilder("?spring,?") .append(Constants.EXTRACTOR_CONF_PATH).append(",").append(Constants.EXTRACTOR_RMI_CONF_PATH) .toString(), bse); } throw new SpringContextLoadException( new StringBuilder("?spring,?") .append(Constants.EXTRACTOR_CONF_PATH).append(",") .append(Constants.EXTRACTOR_RMI_CONF_PATH).toString(), bse); } catch (BeanCreationException ce) { // BEAN,?RMI?? log.error(new StringBuilder("?spring,?BEAN,") .append(Constants.EXTRACTOR_CONF_PATH).append(",").append(Constants.EXTRACTOR_RMI_CONF_PATH) .append(",").append(ce.getMessage()).toString()); if (log.isDebugEnabled()) { log.error(new StringBuilder("?spring,?BEAN") .append(Constants.EXTRACTOR_CONF_PATH).append(",").append(Constants.EXTRACTOR_RMI_CONF_PATH) .toString(), ce); } throw new SpringContextLoadException( new StringBuilder("?spring,?BEAN,") .append(Constants.EXTRACTOR_CONF_PATH).append(",") .append(Constants.EXTRACTOR_RMI_CONF_PATH).toString(), ce); } }
From source file:com.opengamma.language.connector.Main.java
/** * Entry point from the service wrapper - starts the service. * /*ww w . ja v a 2 s. c o m*/ * @return null if the service started properly, otherwise a string for display to the user describing why the stack wasn't started */ public static String svcStart() { try { s_logger.info("Starting OpenGamma language integration service"); s_springContext = new LanguageSpringContext(); return null; } catch (final BeanCreationException e) { s_logger.error("Exception thrown", e); Throwable t = e; do { t = t.getCause(); } while (t instanceof BeanCreationException); if (t != null) { return t.getMessage(); } else { return e.getMessage(); } } catch (final Throwable t) { s_logger.error("Exception thrown", t); return t.getMessage(); } }
From source file:com.sourceallies.beanoh.BeanCreationExceptionTestCase.java
public void assertMissing(String missingBeanId) { try {/* w w w . ja v a2 s . c om*/ assertContextLoading(); fail(); } catch (BeanCreationException e) { assertTrue(e.getMessage().contains("No bean named '" + missingBeanId + "' is defined")); } }
From source file:com.capgemini.archaius.spring.CamelPropertiesMissingFileIsNotOKTest.java
@Test public void missingSpringPropertiesFilesIsNotOkIfIgnoreResourceNotFoundPropertySetToFalse() { // Load the context try {//from ww w. j a v a2s . co m new ClassPathXmlApplicationContext("camel/camelPropertiesMissingFileIsNotOKTest.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) { assertTrue(ex.getMessage().startsWith( "Error creating bean with name 'com.capgemini.archaius.spring.ArchaiusBridgePropertyPlaceholderConfigurer#0' defined in class path resource [camel/camelPropertiesMissingFileIsNotOKTest.xml]: Error setting property values")); } }
From source file:com.cloudera.cli.validator.Main.java
/** * From the arguments, run the validation. * * @param args command line arguments/*from w w w. ja va2s . c o m*/ * @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:cf.spring.servicebroker.ServiceBrokerConfigTest.java
@Test public void serviceBrokerRequiresProvisionAnnotation() { try (ConfigurableApplicationContext context = new AnnotationConfigApplicationContext( MissingProvisionAnnotationServiceBrokerConfig.class)) { fail("Should have thrown " + BeanCreationException.class.getName()); } catch (BeanCreationException e) { assertTrue(e.getMessage().contains("must have method with @cf.spring.servicebroker.Provision")); }//from w w w . j ava 2 s.c o m }
From source file:cf.spring.servicebroker.ServiceBrokerConfigTest.java
@Test public void serviceBrokerRequiresSingleProvisionAnnotation() { try (ConfigurableApplicationContext context = new AnnotationConfigApplicationContext( DoubleProvisionAnnotationServiceBrokerConfig.class)) { fail("Should have thrown " + BeanCreationException.class.getName()); } catch (BeanCreationException e) { assertTrue(e.getMessage().contains("ONE method with @cf.spring.servicebroker.Provision")); }/*from w ww. j a va 2 s. co m*/ }