Search in sources :

Example 26 with SpringApplication

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

the class ConfigFileApplicationListenerTests method propertySourceAnnotationMultipleLocationsAndName.

@Test
public void propertySourceAnnotationMultipleLocationsAndName() throws Exception {
    SpringApplication application = new SpringApplication(WithPropertySourceMultipleLocationsAndName.class);
    application.setWebApplicationType(WebApplicationType.NONE);
    ConfigurableApplicationContext context = application.run();
    String property = context.getEnvironment().getProperty("the.property");
    assertThat(property).isEqualTo("frommorepropertiesfile");
    assertThat(context.getEnvironment()).has(matchingPropertySource("foo"));
    context.close();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) SpringApplication(org.springframework.boot.SpringApplication) Test(org.junit.Test)

Example 27 with SpringApplication

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

the class ConfigFileApplicationListenerTests method profileSubDocumentInSameProfileSpecificFile.

@Test
public void profileSubDocumentInSameProfileSpecificFile() throws Exception {
    // gh-340
    SpringApplication application = new SpringApplication(Config.class);
    application.setWebApplicationType(WebApplicationType.NONE);
    this.context = application.run("--spring.profiles.active=activeprofilewithsubdoc");
    String property = this.context.getEnvironment().getProperty("foobar");
    assertThat(property).isEqualTo("baz");
}
Also used : SpringApplication(org.springframework.boot.SpringApplication) Test(org.junit.Test)

Example 28 with SpringApplication

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

the class DelegatingApplicationListenerTests method orderedInitialize.

@Test
public void orderedInitialize() throws Exception {
    TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, "context.listener.classes=" + MockInitB.class.getName() + "," + MockInitA.class.getName());
    this.listener.onApplicationEvent(new ApplicationEnvironmentPreparedEvent(new SpringApplication(), new String[0], this.context.getEnvironment()));
    this.context.getBeanFactory().registerSingleton("testListener", this.listener);
    this.context.refresh();
    assertThat(this.context.getBeanFactory().getSingleton("a")).isEqualTo("a");
    assertThat(this.context.getBeanFactory().getSingleton("b")).isEqualTo("b");
}
Also used : SpringApplication(org.springframework.boot.SpringApplication) ApplicationEnvironmentPreparedEvent(org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent) Test(org.junit.Test)

Example 29 with SpringApplication

use of org.springframework.boot.SpringApplication in project jphp by jphp-compiler.

the class PWebServer method __construct.

@Signature
public void __construct(Invoker invoker) {
    application = new SpringApplication(WebServerConfig.class);
    defaultProperties = new HashMap<>();
    defaultProperties.put("_server.id", id);
    defaultProperties.put("server.port", 8080);
    application.setDefaultProperties(defaultProperties);
    onRequest = invoker;
    importAutoloaders = true;
    isolated = true;
    hotReload = true;
    WebServerController.registerServer(this);
}
Also used : SpringApplication(org.springframework.boot.SpringApplication) WebServerConfig(org.develnext.jphp.ext.webserver.WebServerConfig)

Example 30 with SpringApplication

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

the class AutoConfigurationReportLoggingInitializerTests method logsDebugOnError.

@Test
public void logsDebugOnError() {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    this.initializer.initialize(context);
    context.register(ErrorConfig.class);
    try {
        context.refresh();
        fail("Did not error");
    } catch (Exception ex) {
        this.initializer.onApplicationEvent(new ApplicationFailedEvent(new SpringApplication(), new String[0], context, ex));
    }
    assertThat(this.debugLog.size()).isNotEqualTo(0);
    assertThat(this.infoLog.size()).isEqualTo(0);
}
Also used : ApplicationFailedEvent(org.springframework.boot.context.event.ApplicationFailedEvent) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) SpringApplication(org.springframework.boot.SpringApplication) LogConfigurationException(org.apache.commons.logging.LogConfigurationException) Test(org.junit.Test)

Aggregations

SpringApplication (org.springframework.boot.SpringApplication)64 Test (org.junit.Test)45 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)14 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)7 HashMap (java.util.HashMap)6 ApplicationStartingEvent (org.springframework.boot.context.event.ApplicationStartingEvent)5 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)4 ApplicationFailedEvent (org.springframework.boot.context.event.ApplicationFailedEvent)4 JoranException (ch.qos.logback.core.joran.spi.JoranException)3 ObjectName (javax.management.ObjectName)3 ApplicationPreparedEvent (org.springframework.boot.context.event.ApplicationPreparedEvent)3 ApplicationReadyEvent (org.springframework.boot.context.event.ApplicationReadyEvent)3 JavaLoggingSystem (org.springframework.boot.logging.java.JavaLoggingSystem)3 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)3 StandardEnvironment (org.springframework.core.env.StandardEnvironment)3 File (java.io.File)2 LogConfigurationException (org.apache.commons.logging.LogConfigurationException)2 ApplicationEnvironmentPreparedEvent (org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent)2 AbstractLoggingSystem (org.springframework.boot.logging.AbstractLoggingSystem)2 LoggingSystem (org.springframework.boot.logging.LoggingSystem)2