Issue
I've just built my Spring project using GraalVM native image like so:
mvn -Pnative -DskipTests clean package
Which gives me a native executable file. When I start it though, it seems like it doesn't have any active profile set. I would like to do something like this:
./my-native-app --spring.profiles.active=production
How can I achieve that?
Solution
The profiles cannot be activated on runtime. They can be processed only at build time, as we can find in the Spring Native Documentation:
https://docs.spring.io/spring-native/docs/current/reference/htmlsingle/#aot-bean-factory-preparation
"A profile is a special sort of condition so these are also evaluated at build-time. It is recommended to avoid the use of profiles as processing them at build-time does not allow you to enable or disable them at runtime anyway. If you want to keep using them, they should be enabled at build-time, for instance by adding the spring.profiles.active property in application.properties."
Answered By - user6354846
Answer Checked By - Clifford M. (JavaFixing Volunteer)