Firstly, there is no way that your application.properties will pick the combined profile (profile: dev & mobile) if you define profiles individually(profile: dev) & also combining it with other profile again(combined with mobile again, I mean dev & mobile). This does not give you any Exceptions, but your combined profile will not get a pick.
The documentation says that, we can combine profiles with symbols & | and other symbols please refer docs, we can make such any complex combinations. But, I don't recommend you define a profile individually & also combine it with other profiles, like you combined dev & mobile, after define dev profile separately.
Following example shows, how it works?
application.yaml
creds:
first: default value
---
spring:
profiles: dev
creds:
first: dev value
---
spring:
profiles: mobile
creds:
first: mobile val
---
spring:
profiles: dev & mobile
creds:
first: dev-mobile value
What happens, if we define a profile individually & combining it with other profile? (like you did).
In this application.yml file, I have defined dev, mobile & combined profile(dev & mobile), and as we know there is also a default profile.
If I don't invoke any profile, as we know, it will pick default profile. For Example, if we are reading a property like this:
@Value("${creds.first}")
String value;
property value: default value
If --spring.profiles.active=dev , then it will pick dev profile.
property value: dev value
If --spring.profiles.active=mobile , then it will pick mobile profile.
property value: mobile val
If --spring.profiles.active=mobile,dev , then here, we have trying to invoke both profiles at same time, ideally, we expect the combined profile should be picked. But it will be not picked. Because, we have defined separate profiles(profile: dev and profile: mobile separately), firstly, it will read the property from mobile profile and then it reads the property from dev profile, if found, then it overrides with property value from dev profile. If not found, it will stick to property value of mobile profile only. I mean to say, it reads
property value: dev value
If --spring.profiles.active=dev,mobile, then here, it first reads the property value from dev profile, then, the again it looks for the property in mobile profile, if found, overrides the value. If not found, it will stick to property value of dev profile only.
That's why it will not read the combined profile (dev & mobile).
How & when it reads combined profile?
As per documentation, it can pick a combined profile, if the mentioned profiles should not have been defined separately elsewhere:
Example: application.yaml
creds:
first: default value
---
spring:
profiles: showcase
creds:
first: showcase value
---
spring:
profiles: dev & mobile
creds:
first: dev-mobile value
here, dev, mobile are combined using & and they are not separately defined elsewhere.
So, now if we invoke --spring.profiles.active=dev,mobile, it will pick the combined profile value
property value: dev-mobile value
Lastly, if --spring.profiles.active=dev or --spring.profiles.active=mobile, it will not pick the combined profile. So, it will sick to default profile.
property value: default value
Sample: https://github.com/donthadineshkumar/multi-profile-document.git