org.springframework.boot.Banner.Mode Java Examples

The following examples show how to use org.springframework.boot.Banner.Mode. 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: RefreshEndpointTests.java    From spring-cloud-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void springMainSourcesEmptyInRefreshCycle() throws Exception {
	this.context = new SpringApplicationBuilder(Empty.class)
			.web(WebApplicationType.NONE).bannerMode(Mode.OFF)
			.properties("spring.cloud.bootstrap.name:none").run();
	RefreshScope scope = new RefreshScope();
	scope.setApplicationContext(this.context);
	// spring.main.sources should be empty when the refresh cycle starts (we don't
	// want any config files from the application context getting into the one used to
	// construct the environment for refresh)
	TestPropertyValues
			.of("spring.main.sources="
					+ ExternalPropertySourceLocator.class.getName())
			.applyTo(this.context);
	ContextRefresher contextRefresher = new ContextRefresher(this.context, scope);
	RefreshEndpoint endpoint = new RefreshEndpoint(contextRefresher);
	Collection<String> keys = endpoint.refresh();
	then(keys.contains("external.message")).as("Wrong keys: " + keys).isFalse();
}
 
Example #2
Source File: RefreshEndpointTests.java    From spring-cloud-commons with Apache License 2.0 6 votes vote down vote up
@Test
public void keysComputedWhenChangesInExternalProperties() throws Exception {
	this.context = new SpringApplicationBuilder(Empty.class)
			.web(WebApplicationType.NONE).bannerMode(Mode.OFF)
			.properties("spring.cloud.bootstrap.name:none").run();
	RefreshScope scope = new RefreshScope();
	scope.setApplicationContext(this.context);
	TestPropertyValues
			.of("spring.cloud.bootstrap.sources="
					+ ExternalPropertySourceLocator.class.getName())
			.applyTo(this.context.getEnvironment(), Type.MAP, "defaultProperties");
	ContextRefresher contextRefresher = new ContextRefresher(this.context, scope);
	RefreshEndpoint endpoint = new RefreshEndpoint(contextRefresher);
	Collection<String> keys = endpoint.refresh();
	then(keys.contains("external.message")).isTrue().as("Wrong keys: " + keys);
}
 
Example #3
Source File: FilterTool.java    From circus-train with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
  // below is output *before* logging is configured so will appear on console
  logVersionInfo();

  try {
    SpringApplication
        .exit(new SpringApplicationBuilder(FilterTool.class)
            .properties("spring.config.location:${config:null}")
            .properties("spring.profiles.active:" + Modules.REPLICATION)
            .properties("instance.home:${user.home}")
            .properties("instance.name:${source-catalog.name}_${replica-catalog.name}")
            .bannerMode(Mode.OFF)
            .registerShutdownHook(true)
            .build()
            .run(args));
  } catch (BeanCreationException e) {
    Throwable mostSpecificCause = e.getMostSpecificCause();
    if (mostSpecificCause instanceof BindException) {
      printFilterToolHelp(((BindException) mostSpecificCause).getAllErrors());
    }
    throw e;
  }
}
 
Example #4
Source File: DeployerApplication.java    From spring-cloud-cli with Apache License 2.0 6 votes vote down vote up
private DeployerProperties loadCloudProperties() {

		final ConfigurableApplicationContext context = new SpringApplicationBuilder(
				PropertyPlaceholderAutoConfiguration.class, DeployerConfiguration.class)
						.bannerMode(Mode.OFF).logStartupInfo(false).web(WebApplicationType.NONE)
						.properties("spring.config.name=cloud", "logging.level.ROOT=OFF",
								"spring.cloud.launcher.list=true",
								"launcher.version=" + getVersion())
						.run(this.args);
		try {
			return context.getBean(DeployerProperties.class);
		}
		finally {
			context.close();
		}
	}
 
Example #5
Source File: GetMetricTableSplitPoints.java    From timely with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {

        try (ConfigurableApplicationContext ctx = new SpringApplicationBuilder(SpringBootstrap.class)
                .bannerMode(Mode.OFF).web(WebApplicationType.NONE).run(args)) {
            Configuration conf = ctx.getBean(Configuration.class);

            final Map<String, String> properties = new HashMap<>();
            Accumulo accumuloConf = conf.getAccumulo();
            properties.put("instance.name", accumuloConf.getInstanceName());
            properties.put("instance.zookeeper.host", accumuloConf.getZookeepers());
            final ClientConfiguration aconf = ClientConfiguration.fromMap(properties);
            final Instance instance = new ZooKeeperInstance(aconf);
            Connector con = instance.getConnector(accumuloConf.getUsername(),
                    new PasswordToken(accumuloConf.getPassword()));
            Scanner s = con.createScanner(conf.getMetaTable(),
                    con.securityOperations().getUserAuthorizations(con.whoami()));
            try {
                s.setRange(new Range(Meta.METRIC_PREFIX, true, Meta.TAG_PREFIX, false));
                for (Entry<Key, Value> e : s) {
                    System.out.println(e.getKey().getRow().toString().substring(Meta.METRIC_PREFIX.length()));
                }
            } finally {
                s.close();
            }
        }
    }
 
Example #6
Source File: RetryableRestOperationsTest.java    From x-pipe with Apache License 2.0 6 votes vote down vote up
@Test
public void retryableRestOperationsFailAndRetrySuccessTest() throws InterruptedException {
	ctx.close();
	RestOperations restOperations = RestTemplateFactory.createCommonsHttpRestTemplate(10, 100, 5000, 5000, 30,
			RetryPolicyFactories.newRestOperationsRetryPolicyFactory(100));
	Thread appStartThread = new Thread(new Runnable() {
		@Override
		public void run() {
			logger.info(remarkableMessage("New SpringApplication"));
			SpringApplication app2 = new SpringApplication(SimpleTestSpringServer.class);
			app2.setBannerMode(Mode.OFF);
			ctx = app2.run("");
			ctx.start();
		}
	});
	appStartThread.start();
	String response = restOperations.getForObject(generateRequestURL("/test"), String.class);
	assertEquals(targetResponse, response);
	appStartThread.join();
}
 
Example #7
Source File: RefreshEndpointTests.java    From spring-cloud-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void shutdownHooksCleaned() {
	try (ConfigurableApplicationContext context = new SpringApplicationBuilder(
			Empty.class).web(WebApplicationType.NONE).bannerMode(Mode.OFF).run()) {
		RefreshScope scope = new RefreshScope();
		scope.setApplicationContext(context);
		ContextRefresher contextRefresher = new ContextRefresher(context, scope);
		RefreshEndpoint endpoint = new RefreshEndpoint(contextRefresher);
		int count = countShutdownHooks();
		endpoint.refresh();
		int after = countShutdownHooks();
		then(count).isEqualTo(after).as("Shutdown hooks not cleaned on refresh");
	}
}
 
Example #8
Source File: RefreshEndpointTests.java    From spring-cloud-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void keysComputedWhenOveridden() throws Exception {
	this.context = new SpringApplicationBuilder(Empty.class)
			.web(WebApplicationType.NONE).bannerMode(Mode.OFF)
			.properties("spring.cloud.bootstrap.name:none").run();
	RefreshScope scope = new RefreshScope();
	scope.setApplicationContext(this.context);
	this.context.getEnvironment().setActiveProfiles("override");
	ContextRefresher contextRefresher = new ContextRefresher(this.context, scope);
	RefreshEndpoint endpoint = new RefreshEndpoint(contextRefresher);
	Collection<String> keys = endpoint.refresh();
	then(keys.contains("message")).isTrue().as("Wrong keys: " + keys);
}
 
Example #9
Source File: RefreshEndpointTests.java    From spring-cloud-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void keysComputedWhenAdded() throws Exception {
	this.context = new SpringApplicationBuilder(Empty.class)
			.web(WebApplicationType.NONE).bannerMode(Mode.OFF)
			.properties("spring.cloud.bootstrap.name:none").run();
	RefreshScope scope = new RefreshScope();
	scope.setApplicationContext(this.context);
	this.context.getEnvironment().setActiveProfiles("local");
	ContextRefresher contextRefresher = new ContextRefresher(this.context, scope);
	RefreshEndpoint endpoint = new RefreshEndpoint(contextRefresher);
	Collection<String> keys = endpoint.refresh();
	then(keys.contains("added")).isTrue().as("Wrong keys: " + keys);
}
 
Example #10
Source File: StartedEventApplicationListener.java    From micro-service with MIT License 5 votes vote down vote up
@Override
public void onApplicationEvent(ApplicationStartedEvent event) {
	
	SpringApplication app = event.getSpringApplication();
       app.setBannerMode(Mode.OFF);
       
	logger.info("1 spring boot启动, StartedEventApplicationListener...");
}
 
Example #11
Source File: RefreshEndpointTests.java    From spring-cloud-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void eventsPublishedInOrder() throws Exception {
	this.context = new SpringApplicationBuilder(Empty.class)
			.web(WebApplicationType.NONE).bannerMode(Mode.OFF).run();
	RefreshScope scope = new RefreshScope();
	scope.setApplicationContext(this.context);
	ContextRefresher contextRefresher = new ContextRefresher(this.context, scope);
	RefreshEndpoint endpoint = new RefreshEndpoint(contextRefresher);
	Empty empty = this.context.getBean(Empty.class);
	endpoint.refresh();
	int after = empty.events.size();
	then(2).isEqualTo(after).as("Shutdown hooks not cleaned on refresh");
	then(empty.events.get(0) instanceof EnvironmentChangeEvent).isTrue();
}
 
Example #12
Source File: RetryableRestOperationsTest.java    From x-pipe with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example #13
Source File: TestMetaServer.java    From x-pipe with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example #14
Source File: DubboBannerApplicationListener.java    From dubbo-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
@Override
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
  if (BANNER_MODE == Banner.Mode.OFF) {
    return;
  }
  String bannerText = this.buildBannerText();
  if (BANNER_MODE == Mode.CONSOLE) {
    System.out.print(bannerText);
  } else if (BANNER_MODE == Mode.LOG) {
    logger.info(bannerText);
  }
}
 
Example #15
Source File: ComparisonTool.java    From circus-train with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
  // below is output *before* logging is configured so will appear on console
  logVersionInfo();

  try {
    SpringApplication
        .exit(new SpringApplicationBuilder(ComparisonTool.class)
            .properties("spring.config.location:${config:null}")
            .properties("spring.profiles.active:" + Modules.REPLICATION)
            .properties("instance.home:${user.home}")
            .properties("instance.name:${source-catalog.name}_${replica-catalog.name}")
            .bannerMode(Mode.OFF)
            .registerShutdownHook(true)
            .build()
            .run(args));
  } catch (BeanCreationException e) {
    Throwable mostSpecificCause = e.getMostSpecificCause();
    if (mostSpecificCause instanceof BindException) {
      printComparisonToolHelp(((BindException) mostSpecificCause).getAllErrors());
      throw e;
    }
    if (e.getMostSpecificCause() instanceof IllegalArgumentException) {
      LOG.error(e.getMessage(), e);
      printComparisonToolHelp(Collections.<ObjectError>emptyList());
    }
  }
}
 
Example #16
Source File: NativeEnvironmentRepository.java    From spring-cloud-config with Apache License 2.0 5 votes vote down vote up
@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: Lnk2Pwn.java    From lnk2pwn with MIT License 5 votes vote down vote up
public static void main(String[] args) throws IOException {    	    	
    new SpringApplicationBuilder(Lnk2Pwn.class)
        .web(WebApplicationType.NONE)
        .bannerMode(Mode.OFF)
        .headless(false)
        .build()
        .run(args);        	
}
 
Example #18
Source File: SpringApplication.java    From spring-javaformat with Apache License 2.0 5 votes vote down vote up
private Banner printBanner(ConfigurableEnvironment environment) {
	if (this.bannerMode == Banner.Mode.OFF) {
		return null;
	}
	ResourceLoader resourceLoader = (this.resourceLoader != null) ? this.resourceLoader
			: new DefaultResourceLoader(getClassLoader());
	SpringApplicationBannerPrinter bannerPrinter = new SpringApplicationBannerPrinter(
			resourceLoader, this.banner);
	if (this.bannerMode == Mode.LOG) {
		return bannerPrinter.print(environment, this.mainApplicationClass, logger);
	}
	return bannerPrinter.print(environment, this.mainApplicationClass, System.out);
}
 
Example #19
Source File: SpringQuartzApp.java    From tutorials with MIT License 4 votes vote down vote up
public static void main(String[] args) {
    new SpringApplicationBuilder(SpringQuartzApp.class).bannerMode(Mode.OFF).run(args);
}
 
Example #20
Source File: Application.java    From example-springboot with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {

    SpringApplication app = new SpringApplication(Application.class);
    app.setBannerMode(Mode.OFF);
    app.run(args);
  }
 
Example #21
Source File: Application.java    From hawkbit-examples with Eclipse Public License 1.0 4 votes vote down vote up
public static void main(final String[] args) {
    new SpringApplicationBuilder().bannerMode(Mode.OFF).sources(Application.class).run(args);
}
 
Example #22
Source File: DubboBannerApplicationListener.java    From dubbo-spring-boot-starter with Apache License 2.0 4 votes vote down vote up
public static void setBANNER_MODE(Banner.Mode bANNER_MODE) {
  BANNER_MODE = bANNER_MODE;
}
 
Example #23
Source File: ConfigServer.java    From spring-cloud-release-tools with Apache License 2.0 4 votes vote down vote up
public static ConfigurableApplicationContext start(String... args) {
	return new SpringApplicationBuilder(ConfigServer.class).bannerMode(Mode.OFF).profiles("native")
			.properties("server.port=8888",
					"spring.cloud.config.server.native.searchLocation:file:./src/test/resources/config/")
			.run(args);
}
 
Example #24
Source File: SpringApplication.java    From spring-javaformat with Apache License 2.0 2 votes vote down vote up
/**
 * Sets the mode used to display the banner when the application runs. Defaults to
 * {@code Banner.Mode.CONSOLE}.
 * @param bannerMode the mode used to display the banner
 */
public void setBannerMode(Banner.Mode bannerMode) {
	this.bannerMode = bannerMode;
}