-
Notifications
You must be signed in to change notification settings - Fork 41.7k
Description
So I think I found a bug in the way Spring native handles profile-specific property files. Or if it isn't a bug, at least it is very confusing to me and probably would need clarification in documentation.
I am building a simple spring-boot application containing only: spring-boot-starter-actuator, spring-boot-starter-web. Version is defined: <spring-boot.version>4.0.0</spring-boot.version>.
I then build a native image, with "prod" profile enabled.
[INFO] --- spring-boot:4.0.0:process-aot (process-aot) @ spring-native-bug-reproducer ---
[...]
2025-12-05T12:38:22.639+01:00 INFO 17844 --- [ main] io.github.bbortt.spring.bug.App : The following 1 profile is active: "prodAnd I also passed a <buildArg>--spring.profiles.active=prod</buildArg> to the <artifactId>native-maven-plugin</artifactId>. It looks to me like this is being respected, because the resulting image says so:
$ docker run --rm docker.io/bbortt/spring-native-bug-reproducer:latest
[...]
2025-12-05T11:42:05.776Z INFO 1 --- [ main] io.github.bbortt.spring.bug.App : The following 1 profile is active: "prod"However, the file resources/application-prod.yaml is not being loaded. Properties defined in profile-related property sources are not present in the native image. I even explicitly tried printing them out:
2025-12-05T11:53:25.835Z INFO 1 --- [ main] io.github.bbortt.spring.bug.App : normalProperty=defined, prodProperty=undefinedDespite having an impact on the build process, but not during runtime. Why "impact during build process"? Well, if you specify a different management.server.port compared to server.port in resources/application-prod.yaml actuator will expect management.server.port to be defined during runtime. But it is not! The results in an exception being thrown:
Caused by: java.lang.IllegalStateException: 'port' must not be null
at org.springframework.util.Assert.state(Assert.java:80)
at org.springframework.boot.actuate.autoconfigure.web.server.ManagementWebServerFactoryCustomizer.customize(ManagementWebServerFactoryCustomizer.java:108)So, it clearly expects the management.server.port to be different, but somehow it is not present during runtime. Funny thing is, if you specify MANAGEMENT_SERVER_PORT via environment variable, everything works just fine.
Two more things: The file itself is present on the classpath. And explicitly loading it does not help!
I would argue that whatever impacts the build lifecycle of native images should also be present or working during runtime. Thoughts, anyone? 😉