PK creative Spring Festival, I am participating in the “Spring Festival creative submission contest”, please see: Spring Festival creative submission Contest

2022! Year of the Tiger is coming ~ let’s take a look as a back-end development how to study how to add some New Year atmosphere to our IDEA, like this: 2022 Happy

✏️springboot Specifies a custom banner

Method 1: Root path banner.txt

Create a banner. TXT file under Resources and copy the banner content into it. Springboot will read the file and print it.

Spring Boot Banner online generation tool

The content of banner.txt is as follows:

█ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ ░ ░ ░ █ █ ░ ░ ░ █ █ █ ░ ░ ░ █ █ ░ ░ ░ █ ░ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ ░ ░ █ ░ █ █ ░ █ ░ ░ █ ░ ░ █ ░ █ █ █ █ █ █ █ █ ░ █ █ ░ ░ ░ █ █ ░ █ █ ░ ░ ░ █ █ ░ ░ █ █ █ █ █ █ █ ░ █ █ ░ █ █ █ █ █ █ █ ░ █ █ █ █ █ █ ░ ░ ░ ░ ░ ░ █ █ ░ █ █ ░ █ █ ░ █ █ ░ █ █ ░ ░ █ █ █ █ ░ ░ ░ █ █ ░ █ █ ░ ░ █ ░ ░ ░ █ █ ░ ░ ░ █ █ █ █ █ █ █ █ █ ░ █ █ █ █ █ █ ░ █ █ █ █ █ █ ░ █ █ █ ░ █ ░ █ █ █ ░ █ █ ░ █ █ █ █ ░ ░ ░ ░ █ █ ░ █ █ ░ ░ ░ ░ █ █ ░ ░ ░ █ █ ░ █ █ █ █ █ █ ░ █ █ █ █ ░ █ █ █ █ █ █ ░ █ █ █ █ █ █ ░ █ █ ░ █ █ ░ ░ █ █ █ █ █ █ █ █ ░ █ █ ░ █ █ █ █ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░Copy the code

Start the SpringBoot project and print:

Method 2: Customize the banner image

We can use GIF type image file, let springBoot boot when the frame print several times more banner, prepare GIF file

  • Banner1. GIF:

  • Fireworks. GIF:

Configure the GIF path

spring:
  banner:
    image:
      location: classpath:myBanner/banner1.gif
# location: classpath:myBanner/fireworks.gif
Copy the code

Fireworks. GIF launch effect:

Omit... @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ 8 @ @ @ @ & @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @@@@@@.8@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@.@@@@@@@*@@@#@@@o8 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@. @@8@o#:.@@#:@o#@#@@@@@@@@@@@@@@@@@@@@@@@@  @@@@@@@@@@@@@@@@@@@@@@@o@#o@@@*@ @@ :.@8 @8@@ @#8@@**o@@@@@@@@@@@@@@@@@@@@@@@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ 88 @ @ @ * @ @ & @ * @ # @ : 8.. 8o*@: o@ @ # @@:@@@@@@@@@@@@@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 @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ #@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @. @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ ░ ░ ░ █ █ ░ ░ ░ █ █ █ ░ ░ ░ █ █ ░ ░ ░ █ ░ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ ░ ░ █ ░ █ █ ░ █ ░ ░ █ ░ ░ █ ░ █ █ █ █ █ █ █ █ ░ █ █ ░ ░ ░ █ █ ░ █ █ ░ ░ ░ █ █ ░ ░ █ █ █ █ █ █ █ ░ █ █ ░ █ █ █ █ █ █ █ ░ █ █ █ █ █ █ ░ ░ ░ ░ ░ ░ █ █ ░ █ █ ░ █ █ ░ █ █ ░ █ █ ░ ░ █ █ █ █ ░ ░ ░ █ █ ░ █ █ ░ ░ █ ░ ░ ░ █ █ ░ ░ ░ █ █ █ █ █ █ █ █ █ ░ █ █ █ █ █ █ ░ █ █ █ █ █ █ ░ █ █ █ ░ █ ░ █ █ █ ░ █ █ ░ █ █ █ █ ░ ░ ░ ░ █ █ ░ █ █ ░ ░ ░ ░ █ █ ░ ░ ░ █ █ ░ █ █ █ █ █ █ ░ █ █ █ █ ░ █ █ █ █ █ █ ░ █ █ █ █ █ █ ░ █ █ ░ █ █ ░ ░ █ █ █ █ █ █ █ █ ░ █ █ ░ █ █ █ █ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ After r SELF destruction 2022-01-10 11:23:15.146 INFO 109632 -- [main] com.ljw.Application: Starting Application using Java 1.8.0_202 on LAPTOP-HTA2F6RV with PID 109632 (E:\project\private\github\java-guide\banner-spring-boot\target\classes started by ljw in E:\project\private\ Github \ Java-Guide) 2022-01-10 11:23:15.148 INFO 109632 -- [main] com.ljw.Application: No active profile set, falling back to default profiles: Default 2022-01-10 11:23:15.436 INFO 109632 -- [main] com.ljw.Application: Started Application in 3.027 seconds (JVM running for 3.643) Process finished with exit code 0Copy the code

Banner1.gif launch effect:

@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @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█ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ ░ ░ ░ █ █ ░ ░ ░ █ █ █ ░ ░ ░ █ █ ░ ░ ░ █ ░ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ █ ░ ░ █ ░ █ █ ░ █ ░ ░ █ ░ ░ █ ░ █ █ █ █ █ █ █ █ ░ █ █ ░ ░ ░ █ █ ░ █ █ ░ ░ ░ █ █ ░ ░ █ █ █ █ █ █ █ ░ █ █ ░ █ █ █ █ █ █ █ ░ █ █ █ █ █ █ ░ ░ ░ ░ ░ ░ █ █ ░ █ █ ░ █ █ ░ █ █ ░ █ █ ░ ░ █ █ █ █ ░ ░ ░ █ █ ░ █ █ ░ ░ █ ░ ░ ░ █ █ ░ ░ ░ █ █ █ █ █ █ █ █ █ ░ █ █ █ █ █ █ ░ █ █ █ █ █ █ ░ █ █ █ ░ █ ░ █ █ █ ░ █ █ ░ █ █ █ █ ░ ░ ░ ░ █ █ ░ █ █ ░ ░ ░ ░ █ █ ░ ░ ░ █ █ ░ █ █ █ █ █ █ ░ █ █ █ █ ░ █ █ █ █ █ █ ░ █ █ █ █ █ █ ░ █ █ ░ █ █ ░ ░ █ █ █ █ █ █ █ █ ░ █ █ ░ █ █ █ █ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ After r R is done, I am not going to do anything about it. After R R is done, I am not going to do anything about it. Starting Application using Java 1.8.0_202 on LAPTOP-HTA2F6RV with PID 81288 (E:\project\private\github\java-guide\banner-spring-boot\target\classes started by ljw in E:\project\ Private \ Github \ Java-Guide) 2022-01-10 11:13:36.268 INFO 81288 -- [main] com.ljw.Application: No active profile set, falling back to default profiles: Default 2022-01-10 11:13:36.572 INFO 81288 -- [main] com.ljw.Application: Started Application in 4.772 seconds (JVM running for 5.362) Process finished with exit code 0Copy the code

Here we print both the GIF file and the banner.txt file. We can see that the GIF print is printed according to the number of frames of the GIF.

☀️SpringBoot source code analysis Banner

We will analyze how springboot controls the printing of the banner, springboot boot class, click run in and out to see

@SpringBootApplication
public class Application {
    public static void main(String[] args) { SpringApplication.run(Application.class, args); }}Copy the code
public static ConfigurableApplicationContext run(Class
        primarySource, String... args) {
    return run(new Class[]{primarySource}, args);
}
Copy the code

Here new a class resource class

public static ConfigurableApplicationContext run(Class
       [] primarySources, String[] args) {
    return (new SpringApplication(primarySources)).run(args);
}
Copy the code

A new SpringApplication launcher class returns, goes into this constructor

public SpringApplication(Class
       ... primarySources) {
    this((ResourceLoader)null, primarySources);
}
Copy the code

Again, it calls its own constructor

public SpringApplication(ResourceLoader resourceLoader, Class
       ... primarySources) {
    this.sources = new LinkedHashSet();
    // The mode of the banner is specified at startup
    this.bannerMode = Mode.CONSOLE;
    this.logStartupInfo = true;
    this.addCommandLineProperties = true;
    this.addConversionService = true;
    this.headless = true;
    this.registerShutdownHook = true;
    this.additionalProfiles = Collections.emptySet();
    this.isCustomEnvironment = false;
    this.lazyInitialization = false;
    this.applicationContextFactory = ApplicationContextFactory.DEFAULT;
    this.applicationStartup = ApplicationStartup.DEFAULT;
    this.resourceLoader = resourceLoader;
    Assert.notNull(primarySources, "PrimarySources must not be null");
    this.primarySources = new LinkedHashSet(Arrays.asList(primarySources));
    this.webApplicationType = WebApplicationType.deduceFromClasspath();
    this.bootstrapRegistryInitializers = new ArrayList(this.getSpringFactoriesInstances(BootstrapRegistryInitializer.class));
    this.setInitializers(this.getSpringFactoriesInstances(ApplicationContextInitializer.class));
    this.setListeners(this.getSpringFactoriesInstances(ApplicationListener.class));
    this.mainApplicationClass = this.deduceMainApplicationClass();
}
Copy the code

This constructor initializes some properties by default. Here we can call the corresponding setter at startup to reset the properties, and initialize the Mode of the banner with the statement this.bannerMode = mode. CONSOLE; Let’s click on this enumerated class

@FunctionalInterface
public interface Banner {
    void printBanner(Environment environment, Class
        sourceClass, PrintStream out);

    public static enum Mode {
        OFF,
        CONSOLE,
        LOG;

        private Mode(a) {}}}Copy the code

Banner defines three patterns, which you can literally see in action

  • OFF: close the Banner
  • CONSOLE: Console output
  • LOG: Log output

So let’s go back to run and see what happens when we initialize

public static ConfigurableApplicationContext run(Class
       [] primarySources, String[] args) {
    return (new SpringApplication(primarySources)).run(args);
}
Copy the code

We know that calling new SpringApplication(primarySources) calls the constructor, initializes some default properties, and then calls the run(args) method. Let’s click run to see

public ConfigurableApplicationContext run(String... args) {
    long startTime = System.nanoTime();
    DefaultBootstrapContext bootstrapContext = this.createBootstrapContext();
    ConfigurableApplicationContext context = null;
    this.configureHeadlessProperty();
    SpringApplicationRunListeners listeners = this.getRunListeners(args);
    listeners.starting(bootstrapContext, this.mainApplicationClass);

    try {
        ApplicationArguments applicationArguments = new DefaultApplicationArguments(args);
        ConfigurableEnvironment environment = this.prepareEnvironment(listeners, bootstrapContext, applicationArguments);
        this.configureIgnoreBeanInfo(environment);
        // Print the banner
        Banner printedBanner = this.printBanner(environment);
        context = this.createApplicationContext();
        context.setApplicationStartup(this.applicationStartup);
        this.prepareContext(bootstrapContext, context, environment, listeners, applicationArguments, printedBanner);
        this.refreshContext(context);
        this.afterRefresh(context, applicationArguments);
        Duration timeTakenToStartup = Duration.ofNanos(System.nanoTime() - startTime);
        if (this.logStartupInfo) {
            (new StartupInfoLogger(this.mainApplicationClass)).logStarted(this.getApplicationLog(), timeTakenToStartup);
        }

        listeners.started(context, timeTakenToStartup);
        this.callRunners(context, applicationArguments);
    } catch (Throwable var12) {
        this.handleRunFailure(context, var12, listeners);
        throw new IllegalStateException(var12);
    }

    try {
        Duration timeTakenToReady = Duration.ofNanos(System.nanoTime() - startTime);
        listeners.ready(context, timeTakenToReady);
        return context;
    } catch (Throwable var11) {
        this.handleRunFailure(context, var11, (SpringApplicationRunListeners)null);
        throw newIllegalStateException(var11); }}Copy the code

Banner printedBanner = this.printBanner(environment

private Banner printBanner(ConfigurableEnvironment environment) {
   // Determine whether to print
   if (this.bannerMode == Mode.OFF) {
       return null;
   } else {
       ResourceLoader resourceLoader = this.resourceLoader ! =null ? this.resourceLoader : new DefaultResourceLoader((ClassLoader)null);
       // Create a print object
       SpringApplicationBannerPrinter bannerPrinter = new SpringApplicationBannerPrinter((ResourceLoader)resourceLoader, this.banner);
       // Determine whether to print console or log according to the mode
       return this.bannerMode == Mode.LOG ? bannerPrinter.print(environment, this.mainApplicationClass, logger) : bannerPrinter.print(environment, this.mainApplicationClass, System.out); }}Copy the code

Here is to determine the banner output mode, mode to the console, here click bannerprinter.print () to check

Banner print(Environment environment, Class
        sourceClass, Log logger) {
    // Get a Banner
    Banner banner = this.getBanner(environment);

    try {
        logger.info(this.createStringFromBanner(banner, environment, sourceClass));
    } catch (UnsupportedEncodingException var6) {
        logger.warn("Failed to create String for banner", var6);
    }

    return new SpringApplicationBannerPrinter.PrintedBanner(banner, sourceClass);
}
Copy the code

Here is a statement: Banner Banner = this.getbanner (environment); Get the banner based on the environment, click to see

private Banner getBanner(Environment environment) {
    SpringApplicationBannerPrinter.Banners banners = new SpringApplicationBannerPrinter.Banners();
    // Get an image banner here
    banners.addIfNotNull(this.getImageBanner(environment));
     // Get a text banner here
    banners.addIfNotNull(this.getTextBanner(environment));
    if (banners.hasAtLeastOneBanner()) {
    // Return at least one banner
        return banners;
    } else {
        // This returns the default springBoot banner directly
        return this.fallbackBanner ! =null ? this.fallbackBanner : DEFAULT_BANNER; }}Copy the code

We clearly click on the integration of images: banners. AddIfNotNull (this.getimageBanner (environment));

private Banner getImageBanner(Environment environment) {
    String location = environment.getProperty("spring.banner.image.location");
    if (StringUtils.hasLength(location)) {
        Resource resource = this.resourceLoader.getResource(location);
        return resource.exists() ? new ImageBanner(resource) : null;
    } else {
        // The view image type is defined here
        String[] var3 = IMAGE_EXTENSION;
        int var4 = var3.length;

        for(int var5 = 0; var5 < var4; ++var5) {
            String ext = var3[var5];
            Resource resource = this.resourceLoader.getResource("banner." + ext);
            if (resource.exists()) {
                // If we customize the configuration, it will return immediately and only one banner will be loaded
                return newImageBanner(resource); }}return null; }}Copy the code

Here you can see is that our environment of spring configuration file. The banner. Image. The parameters of the location, will be to load, and will only load a banner, we view the image type is as follows:

static final String[] IMAGE_EXTENSION = new String[]{"gif"."jpg"."png"};
Copy the code

Can configure GIF animation pictures, and order, there is a return.

We look at the text banner: clearly.addifnotnull (this.gettextBanner (environment)); Go in to see

private Banner getTextBanner(Environment environment) {
    String location = environment.getProperty("spring.banner.location"."banner.txt");
    Resource resource = this.resourceLoader.getResource(location);

    try {
        if(resource.exists() && ! resource.getURL().toExternalForm().contains("liquibase-core")) {
            return newResourceBanner(resource); }}catch (IOException var5) {
    }

    return null;
}
Copy the code

The default configuration key is spring.banner. Location and the value name is: banner. TXT, as long as we put banner.

👋 is at the end

  • First of all, thank you very much for reading here, this article is shared here, I wish you a happy New Year!
  • 👍🏻 : have harvest, praise encouragement!
  • ❤️ : Collect articles, easy to look back!
  • 💬 : Comment exchange, mutual progress!