Example usage for org.springframework.boot.context.event ApplicationStartingEvent ApplicationStartingEvent

List of usage examples for org.springframework.boot.context.event ApplicationStartingEvent ApplicationStartingEvent

Introduction

In this page you can find the example usage for org.springframework.boot.context.event ApplicationStartingEvent ApplicationStartingEvent.

Prototype

public ApplicationStartingEvent(SpringApplication application, String[] args) 

Source Link

Document

Create a new ApplicationStartingEvent instance.

Usage

From source file:org.springframework.boot.context.event.EventPublishingRunListener.java

@Override
public void starting() {
    this.initialMulticaster.multicastEvent(new ApplicationStartingEvent(this.application, this.args));
}

From source file:org.springframework.boot.context.logging.LoggingApplicationListenerTests.java

@Before
public void init() throws SecurityException, IOException {
    LogManager.getLogManager()/* www.  j  av  a  2 s .  c  o m*/
            .readConfiguration(JavaLoggingSystem.class.getResourceAsStream("logging.properties"));
    multicastEvent(new ApplicationStartingEvent(new SpringApplication(), NO_ARGS));
    new File("target/foo.log").delete();
    new File(tmpDir() + "/spring.log").delete();
    ConfigurableEnvironment environment = this.context.getEnvironment();
    ConfigurationPropertySources.attach(environment);
}

From source file:org.springframework.boot.context.logging.LoggingApplicationListenerTests.java

@Test
public void parseArgsDoesntReplace() {
    this.initializer.setSpringBootLogging(LogLevel.ERROR);
    this.initializer.setParseArgs(false);
    multicastEvent(new ApplicationStartingEvent(this.springApplication, new String[] { "--debug" }));
    this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader());
    this.logger.debug("testatdebug");
    assertThat(this.outputCapture.toString()).doesNotContain("testatdebug");
}

From source file:org.springframework.boot.context.logging.LoggingApplicationListenerTests.java

@Test
public void shutdownHookIsNotRegisteredByDefault() {
    TestLoggingApplicationListener listener = new TestLoggingApplicationListener();
    System.setProperty(LoggingSystem.class.getName(), TestShutdownHandlerLoggingSystem.class.getName());
    multicastEvent(listener, new ApplicationStartingEvent(new SpringApplication(), NO_ARGS));
    listener.initialize(this.context.getEnvironment(), this.context.getClassLoader());
    assertThat(listener.shutdownHook).isNull();
}

From source file:org.springframework.boot.context.logging.LoggingApplicationListenerTests.java

@Test
public void shutdownHookCanBeRegistered() throws Exception {
    TestLoggingApplicationListener listener = new TestLoggingApplicationListener();
    System.setProperty(LoggingSystem.class.getName(), TestShutdownHandlerLoggingSystem.class.getName());
    TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context,
            "logging.register_shutdown_hook=true");
    multicastEvent(listener, new ApplicationStartingEvent(new SpringApplication(), NO_ARGS));
    listener.initialize(this.context.getEnvironment(), this.context.getClassLoader());
    assertThat(listener.shutdownHook).isNotNull();
    listener.shutdownHook.start();/*ww w. j  a  v a2 s  .  co  m*/
    assertThat(TestShutdownHandlerLoggingSystem.shutdownLatch.await(30, TimeUnit.SECONDS)).isTrue();
}

From source file:org.springframework.boot.context.logging.LoggingApplicationListenerTests.java

@Test
public void closingContextCleansUpLoggingSystem() {
    System.setProperty(LoggingSystem.SYSTEM_PROPERTY, TestCleanupLoggingSystem.class.getName());
    multicastEvent(new ApplicationStartingEvent(this.springApplication, new String[0]));
    TestCleanupLoggingSystem loggingSystem = (TestCleanupLoggingSystem) ReflectionTestUtils
            .getField(this.initializer, "loggingSystem");
    assertThat(loggingSystem.cleanedUp).isFalse();
    multicastEvent(new ContextClosedEvent(this.context));
    assertThat(loggingSystem.cleanedUp).isTrue();
}

From source file:org.springframework.boot.context.logging.LoggingApplicationListenerTests.java

@Test
public void closingChildContextDoesNotCleanUpLoggingSystem() {
    System.setProperty(LoggingSystem.SYSTEM_PROPERTY, TestCleanupLoggingSystem.class.getName());
    multicastEvent(new ApplicationStartingEvent(this.springApplication, new String[0]));
    TestCleanupLoggingSystem loggingSystem = (TestCleanupLoggingSystem) ReflectionTestUtils
            .getField(this.initializer, "loggingSystem");
    assertThat(loggingSystem.cleanedUp).isFalse();
    GenericApplicationContext childContext = new GenericApplicationContext();
    childContext.setParent(this.context);
    multicastEvent(new ContextClosedEvent(childContext));
    assertThat(loggingSystem.cleanedUp).isFalse();
    multicastEvent(new ContextClosedEvent(this.context));
    assertThat(loggingSystem.cleanedUp).isTrue();
    childContext.close();//www  .  j a  va  2 s .co  m
}

From source file:org.springframework.boot.context.logging.LoggingApplicationListenerTests.java

@Test
public void applicationFailedEventCleansUpLoggingSystem() {
    System.setProperty(LoggingSystem.SYSTEM_PROPERTY, TestCleanupLoggingSystem.class.getName());
    multicastEvent(new ApplicationStartingEvent(this.springApplication, new String[0]));
    TestCleanupLoggingSystem loggingSystem = (TestCleanupLoggingSystem) ReflectionTestUtils
            .getField(this.initializer, "loggingSystem");
    assertThat(loggingSystem.cleanedUp).isFalse();
    multicastEvent(new ApplicationFailedEvent(this.springApplication, new String[0],
            new GenericApplicationContext(), new Exception()));
    assertThat(loggingSystem.cleanedUp).isTrue();
}