Making fun with Spring ImageBanner

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:

spring-boot-acii

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:

9gag.png

The result of program execution printed that cool ASCII graphics in the console log:

9gag-logo-acii

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!

Advertisements

Author: nikitapavlenko

I am Software Engineer from Kharkiv, Ukraine. I develop e-commerce web applications using Hybris platfrom mostly using Java.

1 thought on “Making fun with Spring ImageBanner”

  1. 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.

    Liked by 1 person

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s