Search in sources :

Example 56 with SpringApplication

use of org.springframework.boot.SpringApplication in project pinpoint by naver.

the class ProfileResolveListener method onApplicationEvent.

@Override
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
    logger.info(String.format("onApplicationEvent(%s)", event.getClass().getSimpleName()));
    ConfigurableEnvironment environment = event.getEnvironment();
    SpringApplication springApplication = event.getSpringApplication();
    ProfileEnvironmentPostProcessor profileEnvironment = new ProfileEnvironmentPostProcessor();
    profileEnvironment.postProcessEnvironment(environment, springApplication);
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) SpringApplication(org.springframework.boot.SpringApplication)

Example 57 with SpringApplication

use of org.springframework.boot.SpringApplication in project spring-boot by spring-projects.

the class SharedMetadataReaderFactoryContextInitializerTests method checkOrderOfInitializer.

@Test
@SuppressWarnings("unchecked")
void checkOrderOfInitializer() {
    SpringApplication application = new SpringApplication(TestConfig.class);
    application.setWebApplicationType(WebApplicationType.NONE);
    List<ApplicationContextInitializer<?>> initializers = (List<ApplicationContextInitializer<?>>) ReflectionTestUtils.getField(application, "initializers");
    // Simulate what would happen if an initializer was added using spring.factories
    // and happened to be loaded first
    initializers.add(0, new Initializer());
    GenericApplicationContext context = (GenericApplicationContext) application.run();
    BeanDefinition definition = context.getBeanDefinition(SharedMetadataReaderFactoryContextInitializer.BEAN_NAME);
    assertThat(definition.getAttribute("seen")).isEqualTo(true);
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) ApplicationContextInitializer(org.springframework.context.ApplicationContextInitializer) SpringApplication(org.springframework.boot.SpringApplication) List(java.util.List) ApplicationContextInitializer(org.springframework.context.ApplicationContextInitializer) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) Test(org.junit.jupiter.api.Test)

Example 58 with SpringApplication

use of org.springframework.boot.SpringApplication in project spring-boot by spring-projects.

the class MyApplication method main.

public static void main(String[] args) {
    SpringApplication application = new SpringApplication(MyApplication.class);
    application.setBannerMode(Banner.Mode.OFF);
    application.run(args);
}
Also used : SpringApplication(org.springframework.boot.SpringApplication)

Example 59 with SpringApplication

use of org.springframework.boot.SpringApplication in project spring-boot by spring-projects.

the class LoggingApplicationListenerTests method shutdownHookIsRegisteredByDefault.

@Test
void shutdownHookIsRegisteredByDefault() throws Exception {
    TestLoggingApplicationListener listener = new TestLoggingApplicationListener();
    Object registered = ReflectionTestUtils.getField(listener, TestLoggingApplicationListener.class, "shutdownHookRegistered");
    ((AtomicBoolean) registered).set(false);
    System.setProperty(LoggingSystem.class.getName(), TestShutdownHandlerLoggingSystem.class.getName());
    multicastEvent(listener, new ApplicationStartingEvent(this.bootstrapContext, new SpringApplication(), NO_ARGS));
    listener.initialize(this.context.getEnvironment(), this.context.getClassLoader());
    assertThat(listener.shutdownHook).isNotNull();
    listener.shutdownHook.run();
    assertThat(TestShutdownHandlerLoggingSystem.shutdownLatch.await(30, TimeUnit.SECONDS)).isTrue();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SpringApplication(org.springframework.boot.SpringApplication) ApplicationStartingEvent(org.springframework.boot.context.event.ApplicationStartingEvent) LoggingSystem(org.springframework.boot.logging.LoggingSystem) JavaLoggingSystem(org.springframework.boot.logging.java.JavaLoggingSystem) AbstractLoggingSystem(org.springframework.boot.logging.AbstractLoggingSystem) Test(org.junit.jupiter.api.Test)

Example 60 with SpringApplication

use of org.springframework.boot.SpringApplication in project spring-boot by spring-projects.

the class ConfigDataEnvironmentPostProcessorIntegrationTests method setup.

@BeforeEach
void setup() {
    this.application = new SpringApplication(Config.class);
    this.application.setWebApplicationType(WebApplicationType.NONE);
}
Also used : SpringApplication(org.springframework.boot.SpringApplication) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

SpringApplication (org.springframework.boot.SpringApplication)205 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)56 Test (org.junit.Test)43 Test (org.junit.jupiter.api.Test)39 Environment (org.springframework.core.env.Environment)21 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)15 HashMap (java.util.HashMap)9 ApplicationFailedEvent (org.springframework.boot.context.event.ApplicationFailedEvent)9 ApplicationReadyEvent (org.springframework.boot.context.event.ApplicationReadyEvent)9 ApplicationStartingEvent (org.springframework.boot.context.event.ApplicationStartingEvent)9 File (java.io.File)7 SpringApplicationBuilder (org.springframework.boot.builder.SpringApplicationBuilder)7 BeforeEach (org.junit.jupiter.api.BeforeEach)6 JavaLoggingSystem (org.springframework.boot.logging.java.JavaLoggingSystem)6 ApplicationContext (org.springframework.context.ApplicationContext)6 ApplicationPreparedEvent (org.springframework.boot.context.event.ApplicationPreparedEvent)5 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)5 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)4 JoranException (ch.qos.logback.core.joran.spi.JoranException)3 IOException (java.io.IOException)3