Greetings Spring gurus,

Goal

I set out to achieve a simple task; include build.version in the log after enabling Spring buildInfo().

Exception from PropertyAction - Could not find resource [/META-INF/build-info.properties].

I seem unable to convince the ch.qos.logback.core.joran.action.PropertyAction.begin(...) that build-info.properties is present on the classpath. Surely I'm missing something obvious, in-order to allow Logback to resolve the reference in logback-spring.xml:

<property resource="/META-INF/build-info.properties"/>

Results in

{"@timestamp":"2021-01-16T15:23:10.565Z","severity":"DEBUG","service":"springAppName_IS_UNDEFINED","version":"build.version_IS_UNDEFINED","thread":"main","class":"org.springframework.boot.context.logging.ClasspathLoggingApplicationListener","message":"Application failed to start with classpath: unknown"}
{"@timestamp":"2021-01-16T15:23:10.572Z","severity":"ERROR","service":"springAppName_IS_UNDEFINED","version":"build.version_IS_UNDEFINED","thread":"main","class":"org.springframework.boot.SpringApplication","message":"Application run failed","stack_trace":"java.lang.IllegalStateException: Logback configuration error detected: \r\nERROR in ch.qos.logback.core.joran.action.PropertyAction - Could not find resource [/META-INF/build-info.properties].\r\n\tat org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:169)\r\n\tat org.springframework.boot.logging.AbstractLoggingSystem.initializeWithConventions(AbstractLoggingSystem.java:80)\r\n\tat org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:60)\r\n\tat org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:118)\r\n\tat org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:306)\r\n\tat org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:281)\r\n\tat org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:239)\r\n\tat org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:216)\r\n\tat org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)\r\n\tat org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)\r\n\tat org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)\r\n\tat org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)\r\n\tat org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:80)\r\n\tat org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:53)\r\n\tat org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:345)\r\n\tat org.springframework.boot.SpringApplication.run(SpringApplication.java:308)\r\n\tat org.springframework.boot.SpringApplication.run(SpringApplication.java:1237)\r\n\tat org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)\r\n\tat com.example.build.info.logging.BuildInfoLoggingApplication.main(BuildInfoLoggingApplication.java:10)\r\n"}
Exception in thread "main" java.lang.IllegalStateException: Logback configuration error detected: 
ERROR in ch.qos.logback.core.joran.action.PropertyAction - Could not find resource [/META-INF/build-info.properties].
    at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:169)
    at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithConventions(AbstractLoggingSystem.java:80)
    at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:60)
    at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:118)
    at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:306)
    at org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:281)
    at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:239)
    at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:216)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
    at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:80)
    at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:53)
    at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:345)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:308)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
    at com.example.build.info.logging.BuildInfoLoggingApplication.main(BuildInfoLoggingApplication.java:10)

Symptom discovered in 2.3.7.RELEASE, but also reproducible in 2.3.8.RELEASE and 2.4.2.

Steps to reproduce

I've created a spring-boot application that demonstrates the above symptom here: https://github.com/dlehammer/spring-boot-build-info-logging-issue

git clone git@github.com:dlehammer/spring-boot-build-info-logging-issue.git

cd spring-boot-build-info-logging-issue

./gradlew bootRun

My initial findings

This screenshot illustrates that the build-info.properties are present on the classpath, but seemingly not for all classloaders. SpringBoot ERROR in ch.qos.logback.core.joran.action.PropertyAction - Could not find resource [/META-INF/build-info.properties]

My approach is based on this QA from stack overflow Spring-Boot include build-info as SpringProperty in Logback where the outlined approach works for 2.1 in 2019.

Thanks in advance for your time :)

PS. I appreciate the decision in #6000 as fail-fast ensured I wasn't scratching my head over whether or not the properties was reachable for Logback.

Comment From: wilkinsona

Thanks for the sample. The URL that you have provided for the resource is incorrect. The leading / is not needed and the URL should be META-INF/build-info.properties. With this change in place, the resource is loaded successfully when run using bootRun and java -jar.

Comment From: dlehammer

Thanks a lot @wilkinsona 👍

I've updated the sample (d8c3309) and can confirm removing the leading / addresses the symptom and the log includes the version as desired.

Ex.

{"@timestamp":"2021-01-16T23:40:16.300Z","severity":"DEBUG","service":"build-info-logging-demo","version":"0.0.1-SNAPSHOT","thread":"main","class":"org.springframework.boot.context.logging.ClasspathLoggingApplicationListener","message":"Application started with classpath: unknown"}