SpringBoot banner内容获取和打印原理

进入run方法。可以发现有一个printBanner方法

1、进入printBanner方法

	private Banner printBanner(ConfigurableEnvironment environment) {
		if (this.bannerMode == Banner.Mode.OFF) {
			return null;
		}
		ResourceLoader resourceLoader = (this.resourceLoader != null) ? this.resourceLoader
				: new DefaultResourceLoader(getClassLoader());
		SpringApplicationBannerPrinter bannerPrinter = new SpringApplicationBannerPrinter(resourceLoader, this.banner);
		if (this.bannerMode == Mode.LOG) {
			return bannerPrinter.print(environment, this.mainApplicationClass, logger);
		}
		return bannerPrinter.print(environment, this.mainApplicationClass, System.out);
	}

  第一行判断Banner的模式是否关闭,如果关闭直接返回。

2、进入bannerPrinter.print(environment, this.mainApplicationClass, System.out)

	public Banner print(Environment environment, Class<?> sourceClass, PrintStream out) {
		Banner banner = getBanner(environment);
		banner.printBanner(environment, sourceClass, out);
		return new PrintedBanner(banner, sourceClass);
	}

getBanner(environment);是获取
printBanner是打印

还是比较简单,可以查看源码

猜你喜欢

转载自www.cnblogs.com/linlf03/p/12369426.html
今日推荐