I'm trying to print my applications version early in the log before any of my other code has a chance to execute, so that if an error happens the version is included in the log file.
@SpringBootApplication
public class Application {
public static void main( String... args ) {
var ctx = SpringApplication.run( Application.class, args );
ctx.getBeanProvider( BuildProperties.class ).ifAvailable( bp -> {
LogManager.getLogger( Application.class ).info( bp.getArtifact() );
} );
}
}
but the block in ifAvailable doesn't get executed, I'd like to print the version especially.
note: this is in build.gradle.kts
springBoot {
buildInfo() // generates BOOT-INF/classes/META-INF/build-info.properties
}
update fails with no such bean...
@SpringBootApplication
public class Application {
public static void main( String... args ) {
SpringApplication.run( Application.class, args );
}
@Bean
CommandLineRunner runner( BuildProperties bp ) {
return args -> LogManager.getLogger( Application.class ).info( bp.getArtifact() );
}
}
update 2: doesn't have to be after the banner, but has to be early enough that it prints before any validation/errors from custom code.