spring-boot: spring.profiles.active in default properties ignored if defaultProperties contain a value for that key
As per documentation here a boot application is suppose to override properties that is defined in files in the given order.
So consider this situation.
I define spring.profiles.active and set it to dev using SpringApplication.setDefaultProperties which is last in the order. So that my application always has a profile by default.
Now I set spring.profiles.active to prod in my application.yml file and since its in a higher order I would expect this to override what I set earlier above.
But thats not happening, My application doesnt take prod profile and I see this debug log
com.mycompany.myapp.TestApp : Starting TestApp on DESKTOP-3NUQHBI with PID 14436 (D:\Projects\test\testApp\target\classes started by Deepu in D:\Projects\test\testApp)
2016-05-20 17:07:48.045 DEBUG 14436 --- [ restartedMain] com.mycompany.myapp.TestApp : Running with Spring Boot v1.3.5.RELEASE, Spring v4.2.6.RELEASE
2016-05-20 17:07:48.046 INFO 14436 --- [ restartedMain] com.mycompany.myapp.TestApp : The following profiles are active: dev
2016-05-20 17:07:48.046 DEBUG 14436 --- [ restartedMain] o.s.boot.SpringApplication : Loading source class com.mycompany.myapp.TestApp
2016-05-20 17:07:49.085 DEBUG 14436 --- [ restartedMain] o.s.b.c.c.ConfigFileApplicationListener : Activated profiles dev
2016-05-20 17:07:49.100 DEBUG 14436 --- [ restartedMain] o.s.b.c.c.ConfigFileApplicationListener : Profiles already activated, '[prod]' will not be applied
2016-05-20 17:07:49.100 DEBUG 14436 --- [ restartedMain] o.s.b.c.c.ConfigFileApplicationListener : Loaded config file 'classpath:/config/application.yml'
2016-05-20 17:07:49.100 DEBUG 14436 --- [ restartedMain] o.s.b.c.c.ConfigFileApplicationListener : Loaded config file 'classpath:/config/application-dev.yml'
2016-05-20 17:07:49.151 DEBUG 14436 --- [ restartedMain] o.s.b.c.c.ConfigFileApplicationListener : Skipped (empty) config file 'classpath:/config/application-dev.yml' for profile dev
2016-05-20 17:07:49.152 DEBUG 14436 --- [ restartedMain] o.s.b.c.c.ConfigFileApplicationListener : Skipped (empty) config file 'classpath:/config/application.yml' for profile dev
But if I set spring.profiles.active to prod in Command line arguments its working as expected.
I would assume that this is a bug as the behaviour is different from what is documented.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 27 (12 by maintainers)
Commits related to this issue
- Sec3_Chap20-SpringBoot Profile Assn-INC: related code 6 — committed to PierreSQS/spring-core-devops by PierreSQS 2 years ago
@snicoll oh sorry. Yes you are right.