类org.springframework.boot.Banner.Mode源码实例Demo

下面列出了怎么用org.springframework.boot.Banner.Mode的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: circus-train   文件: FilterTool.java

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;
  }
}
 

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();
            }
        }
    }
 

@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();
}
 

@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);
}
 

@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();
}
 

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();
		}
	}
 

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);
}
 
源代码8 项目: lnk2pwn   文件: Lnk2Pwn.java

public static void main(String[] args) throws IOException {    	    	
    new SpringApplicationBuilder(Lnk2Pwn.class)
        .web(WebApplicationType.NONE)
        .bannerMode(Mode.OFF)
        .headless(false)
        .build()
        .run(args);        	
}
 
源代码9 项目: circus-train   文件: ComparisonTool.java

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());
    }
  }
}
 

@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);
  }
}
 
源代码11 项目: x-pipe   文件: TestMetaServer.java

@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();
}
 

@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();
}
 

@Override
public void onApplicationEvent(ApplicationStartedEvent event) {
	
	SpringApplication app = event.getSpringApplication();
       app.setBannerMode(Mode.OFF);
       
	logger.info("1 spring boot启动, StartedEventApplicationListener...");
}
 

@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);
}
 

@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);
}
 

@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();
}
 

@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");
	}
}
 

@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);
	}
}
 

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);
}
 

public static void setBANNER_MODE(Banner.Mode bANNER_MODE) {
  BANNER_MODE = bANNER_MODE;
}
 
源代码21 项目: hawkbit-examples   文件: Application.java

public static void main(final String[] args) {
    new SpringApplicationBuilder().bannerMode(Mode.OFF).sources(Application.class).run(args);
}
 
源代码22 项目: example-springboot   文件: Application.java

public static void main(String[] args) {

    SpringApplication app = new SpringApplication(Application.class);
    app.setBannerMode(Mode.OFF);
    app.run(args);
  }
 
源代码23 项目: tutorials   文件: SpringQuartzApp.java

public static void main(String[] args) {
    new SpringApplicationBuilder(SpringQuartzApp.class).bannerMode(Mode.OFF).run(args);
}
 

/**
 * 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;
}
 
 类所在包
 类方法
 同包方法