Example usage for org.springframework.boot SpringApplication SpringApplication

List of usage examples for org.springframework.boot SpringApplication SpringApplication

Introduction

In this page you can find the example usage for org.springframework.boot SpringApplication SpringApplication.

Prototype

SpringApplication

Source Link

Usage

From source file:com.apipulse.bastion.Main.java

public static void main(String[] args) throws IOException, ClassNotFoundException {
    log.info("Bastion starting. Loading chains");
    final File dir = new File("etc/chains");

    final LinkedList<ActorRef> chains = new LinkedList<ActorRef>();
    for (File file : dir.listFiles()) {
        if (!file.getName().startsWith(".") && file.getName().endsWith(".yaml")) {
            log.info("Loading chain: " + file.getName());
            ChainConfig config = new ChainConfig(IOUtils.toString(new FileReader(file)));
            ActorRef ref = BastionActors.getInstance().initChain(config.getName(),
                    Class.forName(config.getQualifiedClass()));
            Iterator<StageConfig> iterator = config.getStages().iterator();
            while (iterator.hasNext())
                ref.tell(iterator.next(), null);
            chains.add(ref);//  ww  w.  j a  v a  2s  .c  o  m
        }
    }
    SpringApplication app = new SpringApplication();
    HashSet<Object> objects = new HashSet<Object>();
    objects.add(ApiController.class);
    final ConfigurableApplicationContext context = app.run(ApiController.class, args);
    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            try {
                log.info("Bastion shutting down");
                Iterator<ActorRef> iterator = chains.iterator();
                while (iterator.hasNext())
                    iterator.next().tell(new StopMessage(), null);
                Thread.sleep(2000);
                context.stop();
                log.info("Bastion shutdown complete");
            } catch (Exception e) {
            }
        }
    });
}

From source file:org.osiam.Osiam.java

public static void main(String[] args) {
    SpringApplication application = new SpringApplication();
    String command = extractCommand(args);
    OsiamHome osiamHome = new OsiamHome();
    if ("initHome".equals(command)) {
        application.setSources(Collections.<Object>singleton(InitHome.class));
        application.setWebEnvironment(false);
    } else if ("migrateDb".equals(command)) {
        application.setSources(Collections.<Object>singleton(MigrateDb.class));
        application.setWebEnvironment(false);
        osiamHome.shouldInitializeHome(false);
    } else {//from   w  w w  . j  ava  2s. c o  m
        application.setSources(Collections.<Object>singleton(Osiam.class));
    }
    application.addListeners(osiamHome);
    application.setDefaultProperties(DEFAULT_PROPERTIES);
    application.run(args);
}

From source file:org.springframework.boot.autoconfigure.logging.AutoConfigurationReportLoggingInitializerTests.java

@Test
public void logsDebugOnError() {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    this.initializer.initialize(context);
    context.register(ErrorConfig.class);
    try {/* ww w  .  j a  va  2s. c  om*/
        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(), not(equalTo(0)));
    assertThat(this.infoLog.size(), equalTo(0));
}

From source file:org.springframework.boot.autoconfigure.logging.AutoConfigurationReportLoggingInitializerTests.java

@Test
public void logsInfoOnErrorIfDebugDisabled() {
    setupLogging(false, true);// ww  w  .  j a  v a 2s.  c om
    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(), equalTo(0));
    assertThat(this.infoLog.size(), not(equalTo(0)));
}

From source file:org.springframework.boot.autoconfigure.logging.AutoConfigurationReportLoggingInitializerTests.java

@Test
public void noErrorIfNotInitialized() throws Exception {
    this.initializer.onApplicationEvent(new ApplicationFailedEvent(new SpringApplication(), new String[0], null,
            new RuntimeException("Planned")));
    assertThat(this.infoLog.get(0), containsString("Unable to provide auto-configuration report"));
}

From source file:org.springframework.boot.context.initializer.LoggingApplicationContextInitializerTests.java

@Before
public void init() throws SecurityException, IOException {
    LogManager.getLogManager()//from w  w w.  jav a  2 s. c  o  m
            .readConfiguration(JavaLoggingSystem.class.getResourceAsStream("logging.properties"));
    this.initializer.initialize(new SpringApplication(), NO_ARGS);
}

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

@Before
public void init() throws SecurityException, IOException {
    LogManager.getLogManager()//from  w  w  w . j  a  v  a  2  s  .co  m
            .readConfiguration(JavaLoggingSystem.class.getResourceAsStream("logging.properties"));
    this.initializer.onApplicationEvent(new SpringApplicationStartEvent(new SpringApplication(), NO_ARGS));
    new File("target/foo.log").delete();
}

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

@Before
public void init() throws SecurityException, IOException {
    LogManager.getLogManager()//w  w w  .j  a v  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 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();/*  w w  w.j  a  va  2 s. c  o m*/
    assertThat(TestShutdownHandlerLoggingSystem.shutdownLatch.await(30, TimeUnit.SECONDS)).isTrue();
}