Thursday, 16 March 2017

Custom Banner in Spring Boot

Custom Banner
Every time you run your application, you can see a banner being displayed at the beginning of the
application. That banner can be customized in different ways. Listing 3-11 shows how to implement the
org.springframework.boot.Banner interface.

-- src/main/java/com/naarendra/spring/SpringBootSimpleApplication.java
package com.narendra.spring;
import java.io.PrintStream;
import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.core.env.Environment;
@SpringBootApplication
public class SpringBootSimpleApplication {
public static void main(String[] args) {
SpringApplication app = new SpringApplication(SpringBootSimpleApplication.class);
app.setBanner(new Banner() {
@Override
public void printBanner(Environment environment, Class<?> sourceClass,
PrintStream out) {
out.print("\n\n\tThis is my own banner!\n\n".toUpperCase());
}
});
app.run(args);
}
}



You can also create your own ASCII banner and display it. There is a very cool site that creates ASCII art
from text ( http://patorjk.com ).