Saturday 21 July 2018

Spring boot: Customizing the banner

When you ran any spring boot application, you can able to see below banner in the console.




Spring provides a way to customize the banner.
a.   By adding banner.txt
b.   By setting the spring.banner.location property to the location of banner.txt file
c.   By adding banner.gif, banner.jpg, or banner.png image file to your classpath
d.   By setting the spring.banner.image.location property.

By adding banner.txt
Create a 'banner.txt' file and add it in the class path. spring boot application read this banner file and print it in the console.


banner.txt
#    #
#   #    #####      #     ####   #    #  #    #    ##
#  #     #    #     #    #       #    #  ##   #   #  #
###      #    #     #     ####   ######  # #  #  #    #
#  #     #####      #         #  #    #  #  # #  ######
#   #    #   #      #    #    #  #    #  #   ##  #    #
#    #   #    #     #     ####   #    #  #    #  #    #

Application Version : ${application.version}
Application formatted version : ${application.formatted-version}
Spring boot version : ${spring-boot.version}
Spring boot formatted version : ${spring-boot.formatted-version}
Ansi name : ${Ansi.NAME}
Ansi Background name : ${AnsiBackground.NAME}
Application title : ${application.title}


I added banner.txt file in src/main/resources folder.


When I ran Application.java, I seen below data in the console.
#    #
#   #    #####      #     ####   #    #  #    #    ##
#  #     #    #     #    #       #    #  ##   #   #  #
###      #    #     #     ####   ######  # #  #  #    #
#  #     #####      #         #  #    #  #  # #  ######
#   #    #   #      #    #    #  #    #  #   ##  #    #
#    #   #    #     #     ####   #    #  #    #  #    #

Application Version : 
Application formatted version : 
Spring boot version : 2.0.1.RELEASE
Spring boot formatted version :  (v2.0.1.RELEASE)
Ansi name : ${Ansi.NAME}
Ansi Background name : ${AnsiBackground.NAME}
Application title :


Below table summarizes different variables associated with banner.

Variable
Description
${application.version}
The version number of your application, as declared in MANIFEST.MF.
${application.formatted-version}
The version number of your application, as declared in MANIFEST.MF and 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 2.1.0.BUILD-SNAPSHOT.
${spring-boot.formatted-version}
The Spring Boot version that you are using, formatted for display (surrounded with brackets and prefixed with v). For example (v2.1.0.BUILD-SNAPSHOT).
${Ansi.NAME} (or ${AnsiColor.NAME}${AnsiBackground.NAME}${AnsiStyle.NAME})
Where NAME is the name of an ANSI escape code.
${application.title}
The title of your application, as declared in MANIFEST.MF. For exampleImplementation-Title: MyApp is printed as MyApp.

By setting the spring.banner.location property to the location of banner.txt file
Create a file 'application.properties' in classpath and define the variable 'spring.banner.location'.

application.properties
spring.banner.location=file:/C:/Users/krishna/Documents/Study/Spring Boot/banner.txt


By adding banner.gif, banner.jpg, or banner.png image file to your classpath

banner.jpg






By setting the spring.banner.image.location property
application.properties

spring.banner.image.location=file:/C:/Users/krishna/Documents/Study/Spring Boot/banner.jpg




Previous                                                 Next                                                 Home

No comments:

Post a Comment