I believe that most you have seen Spring ASCII logo in your console window on the Spring Boot application start up. Just in case here is an example:
But the interesting thing is that you can create such ASCII graphics easily by your own.
In Spring Boot 1.4 a new class called ImageBanner was introduced. You can play with this class in any project that has spring-boot version 1.4 or greater. So to make some fun I created a simple spring boot application using Spring Initializr and the basic usage of ImageBanner is following:
package com.wordpress.nikitapavlenko; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.ImageBanner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.core.env.Environment; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; @SpringBootApplication public class ImagebannerSpringApplication implements CommandLineRunner { @Autowired private Environment environment; public static void main(String[] args) { SpringApplication.run(ImagebannerSpringApplication.class, args); } @Override public void run(String... strings) throws Exception { Resource imageResource = new ClassPathResource("9gag.png"); ImageBanner imageBanner = new ImageBanner(imageResource); imageBanner.printBanner(environment, getClass(), System.out); } }
Just to clarify I need to mention that Spring boot initilizr creates usual mvn project with src/main/java, src/main/resources folders. The image “9gag.png” was placed to src/main/resources folder and it looks following:
The result of program execution printed that cool ASCII graphics in the console log:
It looks awesome, does not it? You can checkout the code from my github imagebanner-spring-demo or you can try to play with ImageBanner directly in browser imagebanner-demo.herokuapp.com. I created and deployed to heroku small app that can do conversion to ASCII for you.
Thanks for your attention!
There are also banner properties for spring boot applications.
E.g.: “`banner.image.location=classpath:9gag.png“`
could be used to replace default Spring banner with you custom one generated from image.
And if you add “`spring.output.ansi.enabled=always“` your banner and whole spring console output becomes colorful.
LikeLiked by 1 person