no

Personalized Spring Boot Startups: Custom Banners and Build Information

1. Overview By default, when a Spring Boot application starts, it displays a banner. In this article, we will explore the process of creatin...

1. Overview

By default, when a Spring Boot application starts, it displays a banner. In this article, we will explore the process of creating a custom banner and utilizing it within Spring Boot applications.

2. Creating a Banner

Before we begin, it's essential to generate the custom banner, which will appear during the application startup process. You can choose to create the custom banner from scratch or leverage various tools designed for this purpose.

In this example, we are generating CzetsuyaTech's logo from https://devops.datenkollektiv.de/banner.txt/index.html.

Create a new file "banner.txt" inside the resources folder and copy and paste this content. This will print a colored banner with application information.

${AnsiColor.BLUE}  _____ ${AnsiColor.WHITE}         _                          ${AnsiColor.BLUE} _______       ${AnsiColor.WHITE}  _
${AnsiColor.BLUE} / ____|${AnsiColor.WHITE} | | ${AnsiColor.BLUE}|__ __| ${AnsiColor.WHITE} | |
${AnsiColor.BLUE}| | ${AnsiColor.WHITE} _______| |_ ___ _ _ _ _ __ _ ${AnsiColor.BLUE} | |${AnsiColor.WHITE} ___ ___| |__
${AnsiColor.BLUE}| | ${AnsiColor.WHITE}|_ / _ \ __/ __| | | | | | |/ _` | ${AnsiColor.BLUE} | |${AnsiColor.WHITE} / _ \/ __| '_ \
${AnsiColor.BLUE}| |____ ${AnsiColor.WHITE} / / __/ |_\__ \ |_| | |_| | (_| | ${AnsiColor.BLUE} | |${AnsiColor.WHITE}| __/ (__| | | |
${AnsiColor.BLUE} \_____/${AnsiColor.WHITE}/___\___|\__|___/\__,_|\__, |\__,_| ${AnsiColor.BLUE} |_|${AnsiColor.WHITE} \___|\___|_| |_|
${AnsiColor.BLUE} ${AnsiColor.WHITE} __/ |
${AnsiColor.BLUE} ${AnsiColor.WHITE} |___/
${AnsiColor.BRIGHT_GREEN}#application.title# v#application.version#
Build: #build.time#
Powered by Spring Boot ${spring-boot.version}

3. Replacing the Variable Information in the Banner.

To replace the build information in the banner, we will use the replacer plugin.
<plugin>
	<groupId>com.google.code.maven-replacer-plugin</groupId>
	<artifactId>replacer</artifactId>
	<version>1.5.3</version>
	<executions>
	  <execution>
		<phase>prepare-package</phase>
		<goals>
		  <goal>replace</goal>
		</goals>
	  </execution>
	</executions>
	<configuration>
	  <file>target/classes/banner.txt</file>
	  <replacements>
		<replacement>
		  <token>#application.title#</token>
		  <value>${project.artifactId}</value>
		</replacement>
		<replacement>
		  <token>#application.version#</token>
		  <value>${project.version}</value>
		</replacement>
		<replacement>
		  <token>#build.time#</token>
		  <value>${maven.build.timestamp}</value>
		</replacement>
	  </replacements>
	</configuration>
</plugin>

4. Summary

In this short article, we have shown how you can set a customized banner for your Spring application.

Related

spring-cloud 3922280946788795805

Post a Comment Default Comments

item