我想在Spring Boot Application中自定义spring boot banner。我想在我的横幅中显示自定义变量。
class AppProfile {
String title;
String version;
//getter-setter and all other stafs
......................
......................
......................
}
如何在Spring Boot Banner中显示标题,版本?
答案 0 :(得分:1)
这是一种方式:
@SpringBootApplication
public class BootApplication extends SpringBootServletInitializer {
public static void main(final String[] args) {
SpringApplication springApplication = new SpringApplication(BootApplication.class);
springApplication.setBanner(new CustomBanner());
springApplication.run(args);
}
private static class CustomBanner implements Banner {
//@formatter:off
private static final String[] BANNER = {
" ______ ",
" | ____| ",
" | |__ ___ ___ ",
" | __/ _ \\ / _ \\ ",
" | | | (_) | (_) |",
" |_| \\___/ \\___/ ",
" "
};
//@formatter:on
private static final String SPRING_BOOT = " :: Spring Boot :: ";
@Override
public void printBanner(final Environment environment, final Class<?> sourceClass, final PrintStream printStream) {
String padding = "";
for (String line : BANNER) {
printStream.println(line);
}
AppProfile appProfile = new AppProfile();
printStream.println(AnsiOutput.toString(AnsiColor.YELLOW, appProfile.title, AnsiColor.DEFAULT, padding, AnsiStyle.FAINT,
appProfile.version));
printStream.println(AnsiOutput.toString(AnsiColor.GREEN, SPRING_BOOT, AnsiColor.DEFAULT, padding, AnsiStyle.FAINT,
SpringBootVersion.getVersion()));
printStream.println();
}
}
private static class AppProfile {
public String title = " :: Foo App :: ";
public String version = "4.2.12.123";
}
}
答案 1 :(得分:0)
Spring通过在应用程序中添加banner.txt文件来提供覆盖banner的功能。将您的自定义徽标横幅文本添加到/src/main/resources/banner.txt文件。
下面是生成横幅文本的不错工具。