I am planning to migrate my project from 2.7.6 to 3.0.1 and also use the Native image feature. But I see in the release notes that Profiles don't work when building a native image using GraalVM. Our release pipeline is built in a way where the Docker image is built only once and the same is deployed to higher environments. We activate the respective profile based on the environment which helps to pick the right application properties. Is it worth using GraalVM if Profiles are not supported or is there any workaround that I am not aware of?
Asked
Active
Viewed 418 times
2
-
2Profiles do work for loading files what doesn't work is `@Profile` annotations as there is no dynamic loading of beans/configuration files possible. So properties work, dynamic beans based on `@Profile` not. So configuring the database URL and username still works. – M. Deinum Jan 24 '23 at 10:51
-
@M.Deinum When I am running below command , its not picking up the correct profile-specific application properties. ./mvnw -Pnative native:compile -Dspring.profiles.active=local ./target/
-Dspring.profiles.active=local None of this is able to pick the correct properties. – Ladu anand Jan 26 '23 at 05:16 -
Why should it? You are building the application and the -D you are passing are to maven **not** spring boot. You would need to specify those in the spring boot plugin. The properties will be picked up when you run the application with `your-binarey --spring.profiles.active=` or when you apply other properties like `--server.port` those will still be bound. At least afaik. The profile specific beans (or property specific conditionals) won't work (yet, there is a story to improve this). – M. Deinum Jan 26 '23 at 06:14
-
@M.Deinum I have asked the above in new question. Maybe you can have a look at it. https://stackoverflow.com/questions/75242495/profile-specific-application-properties-not-picked-by-spring-boot-3-native-execu – Ladu anand Jan 26 '23 at 07:57
-
@M.Deinum How do we pass the -D in the spring boot plugin? How do I ensure everything works in Dockerfile? Do you have a working example? That would really help because I see a lot of confusion around the native image. – Ladu anand Jan 26 '23 at 08:01