Search in sources :

Example 11 with ApplicationFailedEvent

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);
}
Also used : ApplicationFailedEvent(org.springframework.boot.context.event.ApplicationFailedEvent) SpringApplication(org.springframework.boot.SpringApplication) IOException(java.io.IOException)

Example 12 with ApplicationFailedEvent

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.");
}
Also used : ApplicationFailedEvent(org.springframework.boot.context.event.ApplicationFailedEvent) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) SpringApplication(org.springframework.boot.SpringApplication) Test(org.junit.jupiter.api.Test)

Example 13 with ApplicationFailedEvent

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));
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ApplicationFailedEvent(org.springframework.boot.context.event.ApplicationFailedEvent) DefaultBootstrapContext(org.springframework.boot.DefaultBootstrapContext) SpringApplication(org.springframework.boot.SpringApplication) ApplicationReadyEvent(org.springframework.boot.context.event.ApplicationReadyEvent) ApplicationPreparedEvent(org.springframework.boot.context.event.ApplicationPreparedEvent) ApplicationStartingEvent(org.springframework.boot.context.event.ApplicationStartingEvent)

Aggregations

ApplicationFailedEvent (org.springframework.boot.context.event.ApplicationFailedEvent)13 SpringApplication (org.springframework.boot.SpringApplication)9 Test (org.junit.jupiter.api.Test)6 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)5 Test (org.junit.Test)4 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)4 ApplicationStartingEvent (org.springframework.boot.context.event.ApplicationStartingEvent)3 IOException (java.io.IOException)2 LogConfigurationException (org.apache.commons.logging.LogConfigurationException)2 Assertions.assertThatIllegalStateException (org.assertj.core.api.Assertions.assertThatIllegalStateException)2 ApplicationEnvironmentPreparedEvent (org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent)2 ApplicationStartedEvent (org.springframework.boot.context.event.ApplicationStartedEvent)2 AnnotationConfigServletWebServerApplicationContext (org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext)2 ApplicationContext (org.springframework.context.ApplicationContext)2 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 LinkedHashSet (java.util.LinkedHashSet)1