Skip to content

Allow a programatically configured banner to override the default banner #47705

@mmoayyed

Description

@mmoayyed

Using Spring Boot v4 M3 and JDK 25, I have a simple app that does this:

        new SpringApplicationBuilder()
            .banner(new MyBanner())
            // other stuff happens here
            .run(args);

As the documentation indicates, this is a fallback banner in case no banner is found as a resource. I'd like Spring Boot, if possible, to offer a way where the Banner implementation set here overrides any and all banner resources defined; IOW, let this be the primary banner and not the fallback. Perhaps introduce a new "Banner Mode" option?

The annoyance I am running into is that our app creates its own banner programmatically, and yet if we ship the app with a library that has its own banner.txt on the classpath (i.e. Spring Cloud) our banner is ignored and the resource takes over, which seems to me to be both "as intended" and somewhat odd.

If not, it would be good for the documentation to recommend how such a use case could be handled, so one could define and override their own "banner selection" logic, which at the moment is sort of hidden here:

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

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions