use of org.springframework.boot.context.event.ApplicationFailedEvent in project FredBoat by Frederikam.
the class Launcher method main.
public static void main(String[] args) throws IllegalArgumentException {
// just post the info to the console
if (args.length > 0 && (args[0].equalsIgnoreCase("-v") || args[0].equalsIgnoreCase("--version") || args[0].equalsIgnoreCase("-version"))) {
System.out.println("Version flag detected. Printing version info, then exiting.");
System.out.println(getVersionInfo());
System.out.println("Version info printed, exiting.");
return;
}
log.info(getVersionInfo());
int javaVersionMajor = -1;
try {
javaVersionMajor = Runtime.version().major();
} catch (Exception e) {
log.error("Exception while checking if java 9", e);
}
if (javaVersionMajor != 9) {
log.warn("\n\t\t __ ___ ___ _ _ ___ _ _ ___ \n" + "\t\t \\ \\ / /_\\ | _ \\ \\| |_ _| \\| |/ __|\n" + "\t\t \\ \\/\\/ / _ \\| / .` || || .` | (_ |\n" + "\t\t \\_/\\_/_/ \\_\\_|_\\_|\\_|___|_|\\_|\\___|\n" + "\t\t ");
log.warn("FredBoat only officially supports Java 9. You are running Java {}", Runtime.version());
}
System.setProperty("spring.config.name", "fredboat");
System.setProperty("spring.http.converters.preferred-json-mapper", "gson");
SpringApplication app = new SpringApplication(Launcher.class);
app.addListeners(event -> {
if (event instanceof ApplicationFailedEvent) {
ApplicationFailedEvent failed = (ApplicationFailedEvent) event;
log.error("Application failed", failed.getException());
}
});
app.run(args);
}
use of org.springframework.boot.context.event.ApplicationFailedEvent in project spring-boot by spring-projects.
the class ConditionEvaluationReportLoggingListenerTests method logsInfoOnErrorIfDebugDisabled.
@Test
void logsInfoOnErrorIfDebugDisabled(CapturedOutput output) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
this.initializer.initialize(context);
context.register(ErrorConfig.class);
assertThatExceptionOfType(Exception.class).isThrownBy(context::refresh).satisfies((ex) -> this.initializer.onApplicationEvent(new ApplicationFailedEvent(new SpringApplication(), new String[0], context, ex)));
assertThat(output).contains("Error starting ApplicationContext. To display the conditions report re-run" + " your application with 'debug' enabled.");
}
use of org.springframework.boot.context.event.ApplicationFailedEvent in project spring-boot by spring-projects.
the class RestartApplicationListenerTests method testInitialize.
private void testInitialize(boolean failed) {
Restarter.clearInstance();
RestartApplicationListener listener = new RestartApplicationListener();
DefaultBootstrapContext bootstrapContext = new DefaultBootstrapContext();
SpringApplication application = new SpringApplication();
ConfigurableApplicationContext context = mock(ConfigurableApplicationContext.class);
listener.onApplicationEvent(new ApplicationStartingEvent(bootstrapContext, application, ARGS));
assertThat(Restarter.getInstance()).isNotEqualTo(nullValue());
assertThat(Restarter.getInstance().isFinished()).isFalse();
listener.onApplicationEvent(new ApplicationPreparedEvent(application, ARGS, context));
if (failed) {
listener.onApplicationEvent(new ApplicationFailedEvent(application, ARGS, context, new RuntimeException()));
} else {
listener.onApplicationEvent(new ApplicationReadyEvent(application, ARGS, context, null));
}
}
Aggregations