List of usage examples for org.springframework.beans BeanInstantiationException getMessage
@Override
@Nullable
public String getMessage()
From source file:com.cloudera.cli.validator.Main.java
/** * From the arguments, run the validation. * * @param args command line arguments//w ww . j a v a 2 s . co 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(); } }