Java Code Examples for org.springframework.boot.builder.SpringApplicationBuilder#run()
The following examples show how to use
org.springframework.boot.builder.SpringApplicationBuilder#run() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Launcher.java From SkyEye with GNU General Public License v3.0 | 6 votes |
public static void main(String[] args) { SpringApplicationBuilder builder = new SpringApplicationBuilder(Launcher.class); Set<ApplicationListener<?>> listeners = builder.application().getListeners(); for (Iterator<ApplicationListener<?>> it = listeners.iterator(); it.hasNext();) { ApplicationListener<?> listener = it.next(); if (listener instanceof LoggingApplicationListener) { it.remove(); } } builder.application().setListeners(listeners); ConfigurableApplicationContext context = builder.run(args); LOGGER.info("collector backup start successfully"); KafkaConsumer kafkaConsumer = (KafkaConsumer<byte[], String>) context.getBean("kafkaConsumer"); Task task = (Task) context.getBean("backupTask"); // 优雅停止项目 Runtime.getRuntime().addShutdownHook(new ShutdownHookRunner(kafkaConsumer, task)); task.doTask(); }
Example 2
Source File: Launcher.java From SkyEye with GNU General Public License v3.0 | 6 votes |
public static void main(String[] args) { SpringApplicationBuilder builder = new SpringApplicationBuilder(Launcher.class); Set<ApplicationListener<?>> listeners = builder.application().getListeners(); for (Iterator<ApplicationListener<?>> it = listeners.iterator(); it.hasNext();) { ApplicationListener<?> listener = it.next(); if (listener instanceof LoggingApplicationListener) { it.remove(); } } builder.application().setListeners(listeners); ConfigurableApplicationContext context = builder.run(args); LOGGER.info("collector indexer start successfully"); KafkaConsumer kafkaConsumer = (KafkaConsumer<byte[], String>) context.getBean("kafkaConsumer"); Task task = (Task) context.getBean("indexerTask"); // 优雅停止项目 Runtime.getRuntime().addShutdownHook(new ShutdownHookRunner(kafkaConsumer, task)); task.doTask(); }
Example 3
Source File: Launcher.java From SkyEye with GNU General Public License v3.0 | 6 votes |
public static void main(String[] args) { SpringApplicationBuilder builder = new SpringApplicationBuilder(Launcher.class); Set<ApplicationListener<?>> listeners = builder.application().getListeners(); for (Iterator<ApplicationListener<?>> it = listeners.iterator(); it.hasNext();) { ApplicationListener<?> listener = it.next(); if (listener instanceof LoggingApplicationListener) { it.remove(); } } builder.application().setListeners(listeners); ConfigurableApplicationContext context = builder.run(args); LOGGER.info("collector trace start successfully"); KafkaConsumer kafkaConsumer = (KafkaConsumer<byte[], String>) context.getBean("kafkaConsumer"); Task task = (Task) context.getBean("rpcTraceTask"); // 优雅停止项目 Runtime.getRuntime().addShutdownHook(new ShutdownHookRunner(kafkaConsumer, task)); task.doTask(); }
Example 4
Source File: INCEpTION.java From inception with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws Exception { Optional<JWindow> splash = LoadingSplashScreen .setupScreen(INCEpTION.class.getResource("splash.png")); SpringApplicationBuilder builder = new SpringApplicationBuilder(); // Add the main application as the root Spring context builder.sources(INCEpTION.class).web(SERVLET); // Signal that we may need the shutdown dialog builder.properties("running.from.commandline=true"); init(builder); builder.listeners(event -> { if (event instanceof ApplicationReadyEvent || event instanceof ShutdownDialogAvailableEvent) { splash.ifPresent(it -> it.dispose()); } }); builder.run(args); }
Example 5
Source File: Launcher.java From SkyEye with GNU General Public License v3.0 | 6 votes |
public static void main(String[] args) { SpringApplicationBuilder builder = new SpringApplicationBuilder(Launcher.class); Set<ApplicationListener<?>> listeners = builder.application().getListeners(); for (Iterator<ApplicationListener<?>> it = listeners.iterator(); it.hasNext();) { ApplicationListener<?> listener = it.next(); if (listener instanceof LoggingApplicationListener) { it.remove(); } } builder.application().setListeners(listeners); ConfigurableApplicationContext context = builder.run(args); LOGGER.info("collector metrics start successfully"); KafkaConsumer kafkaConsumer = (KafkaConsumer<byte[], String>) context.getBean("kafkaConsumer"); Task task = (Task) context.getBean("metricsTask"); // 优雅停止项目 Runtime.getRuntime().addShutdownHook(new ShutdownHookRunner(kafkaConsumer, task)); task.doTask(); }
Example 6
Source File: YarnCloudAppServiceApplication.java From spring-cloud-deployer-yarn with Apache License 2.0 | 6 votes |
@Override public void afterPropertiesSet() throws Exception { SpringApplicationBuilder builder = new SpringApplicationBuilder(); builder.web(false); builder.sources(Config.class); SpringYarnBootUtils.addSources(builder, sources.toArray(new Object[0])); SpringYarnBootUtils.addProfiles(builder, profiles.toArray(new String[0])); SpringYarnBootUtils.addApplicationListener(builder, appProperties); if (initializers != null) { builder.initializers(initializers); } SpringYarnBootUtils.addConfigFilesContents(builder, configFilesContents); context = builder.run(args); YarnClient client = context.getBean(YarnClient.class); if (client instanceof ApplicationYarnClient) { yarnClient = ((ApplicationYarnClient) client); } else { throw new IllegalArgumentException("YarnClient need to be instanceof ApplicationYarnClient"); } restTemplate = context.getBean(YarnSystemConstants.DEFAULT_ID_RESTTEMPLATE, RestTemplate.class); springYarnProperties = context.getBean(SpringYarnProperties.class); }
Example 7
Source File: AbstractCfEnvTests.java From java-cfenv with Apache License 2.0 | 5 votes |
public Environment getEnvironment(Map<String, Object> properties) { SpringApplicationBuilder builder = new SpringApplicationBuilder(TestApp.class) .web(WebApplicationType.NONE); if (!CollectionUtils.isEmpty(properties)) { builder.properties(properties); } builder.bannerMode(Banner.Mode.OFF); ApplicationContext applicationContext = builder.run(); Environment environment = applicationContext.getEnvironment(); ((ConfigurableApplicationContext) applicationContext).close(); return environment; }
Example 8
Source File: Application.java From SkyEye with GNU General Public License v3.0 | 5 votes |
public static void main(String[] args) { SpringApplicationBuilder builder = new SpringApplicationBuilder(Application.class); Set<ApplicationListener<?>> listeners = builder.application().getListeners(); for (Iterator<ApplicationListener<?>> it = listeners.iterator(); it.hasNext();) { ApplicationListener<?> listener = it.next(); if (listener instanceof LoggingApplicationListener) { it.remove(); } } builder.application().setListeners(listeners); builder.run(args); LOGGER.info("web start successfully"); }
Example 9
Source File: Launcher.java From SkyEye with GNU General Public License v3.0 | 5 votes |
public static void main(String[] args) { SpringApplicationBuilder builder = new SpringApplicationBuilder(Launcher.class); Set<ApplicationListener<?>> listeners = builder.application().getListeners(); for (Iterator<ApplicationListener<?>> it = listeners.iterator(); it.hasNext();) { ApplicationListener<?> listener = it.next(); if (listener instanceof LoggingApplicationListener) { it.remove(); } } builder.application().setListeners(listeners); builder.run(args); LOGGER.info("服务D start successfully"); // 优雅停止项目 Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { LOGGER.info("try to stop the system"); synchronized (Launcher.class) { RUNNING = false; Launcher.class.notify(); } } }); synchronized (Launcher.class) { while (RUNNING) { try { Launcher.class.wait(); } catch (InterruptedException e) { LOGGER.error("wait error"); e.printStackTrace(); } } } }
Example 10
Source File: Launcher.java From SkyEye with GNU General Public License v3.0 | 5 votes |
public static void main(String[] args) { SpringApplicationBuilder builder = new SpringApplicationBuilder(Launcher.class); Set<ApplicationListener<?>> listeners = builder.application().getListeners(); for (Iterator<ApplicationListener<?>> it = listeners.iterator(); it.hasNext();) { ApplicationListener<?> listener = it.next(); if (listener instanceof LoggingApplicationListener) { it.remove(); } } builder.application().setListeners(listeners); builder.run(args); LOGGER.info("服务B start successfully"); // 优雅停止项目 Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { LOGGER.info("try to stop the system"); synchronized (Launcher.class) { RUNNING = false; Launcher.class.notify(); } } }); synchronized (Launcher.class) { while (RUNNING) { try { Launcher.class.wait(); } catch (InterruptedException e) { LOGGER.error("wait error"); e.printStackTrace(); } } } }
Example 11
Source File: SecretManagerBootstrapConfigurationTests.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
@Test public void configurationDisabled() { SpringApplicationBuilder disabledConfigurationApp = new SpringApplicationBuilder( TestBootstrapConfiguration.class, GcpSecretManagerBootstrapConfiguration.class) .properties("spring.cloud.gcp.secretmanager.project-id=" + PROJECT_NAME) .properties("spring.cloud.gcp.secretmanager.enabled=false") .web(WebApplicationType.NONE); try (ConfigurableApplicationContext c = disabledConfigurationApp.run()) { String secret = c.getEnvironment().getProperty("sm://my-secret"); assertThat(secret).isEqualTo(null); } }
Example 12
Source File: SampleAppIntegrationTest.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
@Test public void testSample() throws Exception { SpringApplicationBuilder sender = new SpringApplicationBuilder(SenderApplication.class) .properties("server.port=8082"); sender.run(); SpringApplicationBuilder receiver = new SpringApplicationBuilder(ReceiverApplication.class) .properties("server.port=8081"); receiver.run(); MultiValueMap<String, Object> map = new LinkedMultiValueMap<>(); String message = "test message " + UUID.randomUUID(); map.add("message", message); map.add("times", 1); this.restTemplate.postForObject("http://localhost:8082/postMessage", map, String.class); boolean messageReceived = false; for (int i = 0; i < 100; i++) { if (baos.toString().contains("Message arrived! Payload: " + message)) { messageReceived = true; break; } Thread.sleep(100); } assertThat(messageReceived).isTrue(); }
Example 13
Source File: SampleAppIntegrationTest.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
@Test public void testSample() throws Exception { // Run Source app SpringApplicationBuilder sourceBuilder = new SpringApplicationBuilder(FunctionalSourceApplication.class) .resourceLoader(new PropertyRemovingResourceLoader("spring-cloud-gcp-pubsub-stream-binder-functional-sample-source")); sourceBuilder.run(); //Run Sink app SpringApplicationBuilder sinkBuilder = new SpringApplicationBuilder(FunctionalSinkApplication.class) .resourceLoader(new PropertyRemovingResourceLoader("spring-cloud-gcp-pubsub-stream-binder-functional-sample-sink")); sinkBuilder.run(); // Post message to Source over HTTP. MultiValueMap<String, Object> map = new LinkedMultiValueMap<>(); String message = "test message " + UUID.randomUUID(); map.add("messageBody", message); map.add("username", "integration-test-user"); RestTemplate restTemplate = new RestTemplate(); URI redirect = restTemplate.postForLocation("http://localhost:8080/postMessage", map); assertThat(redirect.toString()).isEqualTo("http://localhost:8080/index.html"); Awaitility.await().atMost(10, TimeUnit.SECONDS) .until(() -> this.output.getOut() .contains("New message received from integration-test-user: " + message)); }
Example 14
Source File: Launcher.java From SkyEye with GNU General Public License v3.0 | 5 votes |
public static void main(String[] args) { SpringApplicationBuilder builder = new SpringApplicationBuilder(Launcher.class); Set<ApplicationListener<?>> listeners = builder.application().getListeners(); for (Iterator<ApplicationListener<?>> it = listeners.iterator(); it.hasNext();) { ApplicationListener<?> listener = it.next(); if (listener instanceof LoggingApplicationListener) { it.remove(); } } builder.application().setListeners(listeners); builder.run(args); LOGGER.info("alarm start successfully"); // 优雅停止项目 Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { LOGGER.info("try to stop the system"); synchronized (Launcher.class) { RUNNING = false; Launcher.class.notify(); } } }); synchronized (Launcher.class) { while (RUNNING) { try { Launcher.class.wait(); } catch (InterruptedException e) { LOGGER.error("wait error"); e.printStackTrace(); } } } }
Example 15
Source File: MongoCfEnvProcessorTests.java From java-cfenv with Apache License 2.0 | 5 votes |
public Environment getEnvironment() { SpringApplicationBuilder builder = new SpringApplicationBuilder(TestApp.class) .web(WebApplicationType.NONE); builder.bannerMode(Banner.Mode.OFF); ApplicationContext applicationContext = builder.run(); return applicationContext.getEnvironment(); }
Example 16
Source File: NativeEnvironmentRepository.java From spring-cloud-config with Apache License 2.0 | 5 votes |
@Override public Environment findOne(String config, String profile, String label, boolean includeOrigin) { SpringApplicationBuilder builder = new SpringApplicationBuilder( PropertyPlaceholderAutoConfiguration.class); ConfigurableEnvironment environment = getEnvironment(profile); builder.environment(environment); builder.web(WebApplicationType.NONE).bannerMode(Mode.OFF); if (!logger.isDebugEnabled()) { // Make the mini-application startup less verbose builder.logStartupInfo(false); } String[] args = getArgs(config, profile, label); // Explicitly set the listeners (to exclude logging listener which would change // log levels in the caller) builder.application() .setListeners(Arrays.asList(new ConfigFileApplicationListener())); try (ConfigurableApplicationContext context = builder.run(args)) { environment.getPropertySources().remove("profiles"); return clean(new PassthruEnvironmentRepository(environment).findOne(config, profile, label, includeOrigin)); } catch (Exception e) { String msg = String.format( "Could not construct context for config=%s profile=%s label=%s includeOrigin=%b", config, profile, label, includeOrigin); String completeMessage = NestedExceptionUtils.buildMessage(msg, NestedExceptionUtils.getMostSpecificCause(e)); throw new FailedToConstructEnvironmentException(completeMessage, e); } }
Example 17
Source File: Application.java From tutorials with MIT License | 4 votes |
private static void writePID() { SpringApplicationBuilder app = new SpringApplicationBuilder(Application.class).web(WebApplicationType.NONE); app.build().addListeners(new ApplicationPidFileWriter("./bin/shutdown.pid")); app.run(); }
Example 18
Source File: Application.java From hub-detect with Apache License 2.0 | 4 votes |
public static void main(final String[] args) { SpringApplicationBuilder builder = new SpringApplicationBuilder(Application.class); builder.logStartupInfo(false); builder.run(args); }
Example 19
Source File: GrafanaAuth.java From timely with Apache License 2.0 | 4 votes |
protected static ConfigurableApplicationContext initializeContext(String[] args) { SpringApplicationBuilder builder = new SpringApplicationBuilder(SpringBootstrap.class); builder.web(WebApplicationType.NONE); builder.registerShutdownHook(false); return builder.run(args); }
Example 20
Source File: Balancer.java From timely with Apache License 2.0 | 4 votes |
protected static ConfigurableApplicationContext initializeContext(String[] args) { SpringApplicationBuilder builder = new SpringApplicationBuilder(SpringBootstrap.class); builder.web(WebApplicationType.NONE); builder.registerShutdownHook(false); return builder.run(args); }