Including profiles with spring.profiles.include seems to override instead of include -


i'm trying partition configuration properties several spring boot applications. i'm using spring boot 1.1.6, , our configuration properties expressed in yaml in usual application.yml style. i've created various profiles common base parameters, common db parameters, etc. trying use include feature mentioned in spring boot reference docs, seems work override , not include. i.e. opposite of want. given following content in application.yml, have expected property name have value bar when bar profile active, instead gets set foo (from included profile). thought notion of including meant loaded first, , identically named properties set in new profile override included profile. kind of if subclass shadowing field superclass, instance of subclass reflect shadowed value. here's file:

spring:   profiles: foo name: foo  --- # new yaml doc starts here  spring:   profiles:      include: foo   profiles: bar name: bar 

if run in test case "bar" profile explicitly activated, name property still foo:

springapplicationbuilder builder = new springapplicationbuilder(application.class); springapplication app = builder.application(); builder.profiles("bar"); configurableapplicationcontext ctxt = app.run(); string name = ctxt.getenvironment().getproperty("name"); // "foo" surprise 

however, if comment out include:

spring:  profiles: bar #  profiles:  #    include: foo 

and activate 2 profiles explicitly in code:

builder.profiles("foo", "bar"); 

then works expect, , name property set bar. main reason rather handle includes in yaml files it's less impact on actual code, , can manage profile inclusion in 1 place. other approach, i'd have search profile strings , possible @profile annotations in entire project if ever rename profiles. that's more error prone. think more flexible solution explicitly able express whether or not included profile overrides sub profile values or not. maybe like:

spring:   profiles: bar   profiles:     include: foo       override: false 

maybe i'm missing here. there better way of doing this? thanks.

try following foo include override bar, seems working solution

spring:     profiles:         include: bar         active: foo,bar 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -