Search in sources :

Example 46 with SpringApplication

use of org.springframework.boot.SpringApplication in project jhipster-sample-app-hazelcast by jhipster.

the class JhipsterHazelcastSampleApplicationApp method main.

/**
 * Main method, used to run the application.
 *
 * @param args the command line arguments
 */
public static void main(String[] args) {
    SpringApplication app = new SpringApplication(JhipsterHazelcastSampleApplicationApp.class);
    DefaultProfileUtil.addDefaultProfile(app);
    Environment env = app.run(args).getEnvironment();
    String protocol = "http";
    if (env.getProperty("server.ssl.key-store") != null) {
        protocol = "https";
    }
    String hostAddress = "localhost";
    try {
        hostAddress = InetAddress.getLocalHost().getHostAddress();
    } catch (Exception e) {
        log.warn("The host name could not be determined, using `localhost` as fallback");
    }
    log.info("\n----------------------------------------------------------\n\t" + "Application '{}' is running! Access URLs:\n\t" + "Local: \t\t{}://localhost:{}\n\t" + "External: \t{}://{}:{}\n\t" + "Profile(s): \t{}\n----------------------------------------------------------", env.getProperty("spring.application.name"), protocol, env.getProperty("server.port"), protocol, hostAddress, env.getProperty("server.port"), env.getActiveProfiles());
}
Also used : SpringApplication(org.springframework.boot.SpringApplication) Environment(org.springframework.core.env.Environment)

Example 47 with SpringApplication

use of org.springframework.boot.SpringApplication in project x-pipe by ctripcorp.

the class KeeperContainerApplication method main.

public static void main(String[] args) throws Exception {
    SpringApplication application = new SpringApplication(KeeperContainerApplication.class);
    application.setRegisterShutdownHook(false);
    final ConfigurableApplicationContext context = application.run(args);
    final ComponentRegistry registry = initComponentRegistry(context);
    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                logger.info("[run][shutdown][stop]");
                registry.stop();
            } catch (Exception e) {
                logger.error("[run][shutdown][stop]", e);
            }
            try {
                logger.info("[run][shutdown][dispose]");
                registry.dispose();
            } catch (Exception e) {
                logger.error("[run][shutdown][dispose]", e);
            }
            try {
                logger.info("[run][shutdown][destroy]");
                registry.destroy();
            } catch (Exception e) {
                logger.error("[run][shutdown][destroy]", e);
            }
        }
    }));
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ComponentRegistry(com.ctrip.xpipe.api.lifecycle.ComponentRegistry) SpringComponentRegistry(com.ctrip.xpipe.lifecycle.SpringComponentRegistry) SpringApplication(org.springframework.boot.SpringApplication)

Example 48 with SpringApplication

use of org.springframework.boot.SpringApplication in project x-pipe by ctripcorp.

the class RetryableRestOperationsTest method startUp.

@Before
public void startUp() {
    port = randomPort(8081, 9090);
    targetResponse = randomString();
    System.setProperty("server.port", String.valueOf(port));
    System.setProperty("target-response", targetResponse);
    SpringApplication app = new SpringApplication(SimpleTestSpringServer.class);
    app.setBannerMode(Mode.OFF);
    ctx = app.run("");
    ctx.start();
}
Also used : SpringApplication(org.springframework.boot.SpringApplication) Before(org.junit.Before)

Example 49 with SpringApplication

use of org.springframework.boot.SpringApplication in project x-pipe by ctripcorp.

the class TestMetaServer method doStart.

@Override
public void doStart() throws Exception {
    System.setProperty(DefaultDcMetaCache.MEMORY_META_SERVER_DAO_KEY, configFile);
    System.setProperty("TOTAL_SLOTS", String.valueOf(total_slots));
    SpringApplication application = new SpringApplication(TestMetaServer.class);
    application.setBannerMode(Mode.OFF);
    application.setEnvironment(createEnvironment());
    context = application.run(new String[] {});
    TestZkClient client = context.getBean(TestZkClient.class);
    DefaultZkConfig zkConfig = new DefaultZkConfig();
    zkConfig.setZkSessionTimeoutMillis(zkSessionTimeoutMillis);
    client.setZkConfig(zkConfig);
    client.setZkAddress(zkConnectionStr);
    UnitTestServerConfig config = context.getBean(UnitTestServerConfig.class);
    config.setZkAddress(zkConnectionStr);
    config.setMetaServerId(serverId);
    config.setMetaServerPort(serverPort);
    ArrangeTaskTrigger arrangeTaskTrigger = context.getBean(ArrangeTaskTrigger.class);
    arrangeTaskTrigger.setWaitForRestartTimeMills(waitForRestartTimeMills);
    manager = context.getBean(SpringComponentRegistry.class);
    manager.initialize();
    manager.start();
}
Also used : ArrangeTaskTrigger(com.ctrip.xpipe.redis.meta.server.cluster.impl.ArrangeTaskTrigger) SpringComponentRegistry(com.ctrip.xpipe.lifecycle.SpringComponentRegistry) SpringApplication(org.springframework.boot.SpringApplication) UnitTestServerConfig(com.ctrip.xpipe.redis.meta.server.config.UnitTestServerConfig) DefaultZkConfig(com.ctrip.xpipe.zk.impl.DefaultZkConfig) TestZkClient(com.ctrip.xpipe.zk.impl.TestZkClient)

Example 50 with SpringApplication

use of org.springframework.boot.SpringApplication in project x-pipe by ctripcorp.

the class ApplicationTest method testRun.

@Test
public void testRun() throws IOException {
    System.setProperty(AbstractProfile.PROFILE_KEY, AbstractProfile.PROFILE_NAME_PRODUCTION);
    System.setProperty("TOTAL_SLOTS", String.valueOf(16));
    System.setProperty(DefaultDcMetaCache.MEMORY_META_SERVER_DAO_KEY, "metaserver--jq.xml");
    startZk(2181);
    new SpringApplication(MetaServerApplication.class).run();
    waitForAnyKeyToExit();
}
Also used : SpringApplication(org.springframework.boot.SpringApplication) MetaServerApplication(com.ctrip.xpipe.redis.meta.server.MetaServerApplication) Test(org.junit.Test) AbstractMetaServerTest(com.ctrip.xpipe.redis.meta.server.AbstractMetaServerTest)

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