Spring Boot 3.x Native application assembled with Grade does not load corresponding to Spring Profile logging config
Spring Boot Version:
plugins {
id 'java'
id 'org.springframework.boot' version '3.0.5'
id 'io.spring.dependency-management' version '1.1.0'
id 'org.graalvm.buildtools.native' version '0.9.20'
}
Supplied resources: /src/main/resources:
application-prod.yml
application.yml
logback-spring-json.xml
logback-spring.xml
application.yml refers to logback-spring.xml, while application-prod.yml links to logback-spring-json.xml via:
logging:
config: classpath:logback-spring-json.xml
Application Assembly:
./gradlew nativeCompile
Issue:
- Run generated application with no arguments, AKA default profile, it will pickup application.yml and logback-spring.xml - Expected
- Run generated application with
--spring.profiles.active=prod, AKA default profile, it will pickup application-prod.yml and won't use logback-spring-json.xml - an issue
Verification: If you run application in "normal" model it will works as expected, i.e.:
defaultTasks 'bootRun'
bootRun {
args = ["--spring.profiles.active=prod"]
}
will use both application-prod.yml and logback-spring-json.xml as expected
Some initial Ideas: * Was under impression Spring Native does not know anything about "prod" profile and file it refers during compile time, thus it does not include logback-spring-json.xml in binary. * We can confirm that application-prod.yml is included, we can change for instance logging level. * To make sure logback-spring-json.xml is in binary we were trying to use hints:
public class GrafanaToZoomRuntimeHints implements RuntimeHintsRegistrar {
@Override
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
// Register resources in addition to what ConfigDataLocationRuntimeHints already registered
hints.resources().registerPattern("logback-*.xml");
}
}
and then include these from *Application.java:
@ImportRuntimeHints({GrafanaToZoomRuntimeHints.class})
Still no luck. No matter what we try, we cannot provide external logging config either within binary or even outside binary, by telling Spring to use file system reference to config instead of Class Path reference.
Any ideas would be appreciated.
Comment From: wilkinsona
XML-based Logback configuration is loaded during AOT processing and translated into a native-friendly format that is then included in the native image. It's this translated configuration that's then loaded at runtime. Using different configuration at runtime isn't supported. I've added a section to the wiki to document this limitation.