6.Spring Boot 自定义Banner

Spring Boot 自定义Banner

      到这里相信大家应该都见过以下图案。
  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.4.2.RELEASE)
      该图案是在启动Spring Boot的时候在控制台输出的,包含当前使用的Spring Boot的版本,有的时候需要定制自己的Banner,也可能关闭输出Banner。接下来介绍如何更改。

1.关闭Banner

      在启动的时候调用setBannerMode设置即可,代码如下:
	public static void main(String[] args) throws Exception {
		SpringApplication springApplication = new SpringApplication(SampleController.class);
		springApplication.setBannerMode(Banner.Mode.OFF);
		springApplication.run(args);
	}

      Banner.Mode是个内部枚举,有三个值如下:
	enum Mode {

		/**
		 * Disable printing of the banner. 关闭Banner打印输出
		 */
		OFF,

		/**
		 * Print the banner to System.out. 打印Banner 控制台
		 */
		CONSOLE,

		/**
		 * Print the banner to the log file. 打印banner 到日志文件
		 */
		LOG

	}
 

2.更改Banner

      (1)在src/main/resources下新建banner.txt,在该文件中输入你想要的图案即可 。在看《JavaEE开发的颠覆者 Spring Boot实战》一书的时候,作者在书中写了一个网站,可以生成相应的图案,具体大家去试试,网址: Text to ASCII Art Generator (TAAG)。在banner.txt文件中,你可以使用以下的占位符获取当前应用版本等信息,具体如下:
VariableDescription
${application.version}The version number of your application as declared in MANIFEST.MF
 formatted for display (surrounded with brackets and prefixed with v). 
For example (v1.0).
${application.formatted-version}The version number of your application as declared in MANIFEST.MF 
formatted for display (surrounded with brackets and prefixed with v). 
For example (v1.0)
${spring-boot.version}The Spring Boot version that you are using. For example 1.4.2.RELEASE.
${spring-boot.formatted-version}The Spring Boot version that you are using formatted for display 
(surrounded with brackets and prefixed with v). 
For example (v1.4.2.RELEASE).
${Ansi.NAME}
 (or ${AnsiColor.NAME}, 
${AnsiBackground.NAME}, 
${AnsiStyle.NAME})
Where NAME is the name of an ANSI escape code.
See AnsiPropertySource for details.
${application.title}The title of your application as declared in MANIFEST.MF.
 For example Implementation-Title: MyApp is printed as MyApp.


      (2)或者通过springApplication.setBanner(banner);方法,实现Banner接口也一样。
 

 
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值