Spring-cloud-config: bootstrap-xxx.yml is not loaded with spring.profiles.include=xxx

Created on 4 Jan 2017  路  12Comments  路  Source: spring-cloud/spring-cloud-config

As described at here, bootstrap-xxx.yml is loaded with spring.profiles.active=xxx only.
But it does NOT loaded with spring.profiles.include=xxx ( spring.profiles.include comes from Spring Boot).

Sometimes I prefer to use spring.profiles.include to map an other profile.
It would become more useful if spring.profiles.include were supported.

enhancement help wanted

Most helpful comment

@indraneelb1903 generally speaking, if an issue is open, it has not been implemented.

All 12 comments

has this been implemented?

@indraneelb1903 generally speaking, if an issue is open, it has not been implemented.

waiting for it ...

Hi, @jiang-wei @indraneelb1903 @ikeyat I think this issue has been solved by the following commit , would you please check it?

https://github.com/spring-projects/spring-boot/commit/378c4c9535a5fb52f981e111c402902a064b8409

I used Finchley.SR2, it can work, but after update to Finchley.SR3, this issue happened again.
And I just pass "--spring.profiles.include=git" by command args to fixed it as a temp resolution.

Hi @yuanjinyong , I tried Finchley.SR3, and it seems it works correctly.
you can see the sample project here, please use the spring-cloud-config_issue_604 branch.

in bootstrap.yml

spring:
  profiles:
    include: git
foo.bar: this is foo.bar value in bootstrap.yml

in bootstrap-git.yml

foo.bar: this is foo.bar value in bootstrap-git.yml

In application, we can see from the output from the following line , the value of 'foo.bar' is the one in bootstrap-git.yml.

https://github.com/chang-chao/spring-cloud-config-server-sample/blob/0a348dcffda64ce4c290f90a69eb0dabe97427cc/src/main/java/me/changchao/spring/cloud/sample/springcloudconfigserversample/SpringCloudConfigServerSampleApplication.java#L19

Would please provide more information on your usecase or provide a simple project to reproduce the issue ?

This issue is cause by jasypt-spring-boot have conflict with spring-cloud-context-2.0.3.RELEASE.
In spring-cloud-context-2.0.3.RELEASE, have the follow change:
org\springframework\cloud\bootstrapBootstrapApplicationListener.java

public void add(PropertySource<?> source) {
            if (source instanceof EnumerablePropertySource 
                    && !this.names.contains(source.getName())) {
                this.sources.addPropertySource(source);
                this.names.add(source.getName());
            }
        }

to

public void add(PropertySource<?> source) {
            // Only add map property sources added by boot, see gh-476
            if (source instanceof OriginTrackedMapPropertySource 
                    && !this.names.contains(source.getName())) {
                this.sources.addPropertySource(source);
                this.names.add(source.getName());
            }
        }

And after use jasypt, the "PropertySource source" instance will be "com.ulisesbocchio.jasyptspringboot.wrapper.EncryptableMapPropertySourceWrapper", it is an intance of EnumerablePropertySource, but not an intance of OriginTrackedMapPropertySource.

OriginTrackedMapPropertySource is a final class, it can not be extended by EncryptableMapPropertySourceWrapper.

https://github.com/ulisesbocchio/jasypt-spring-boot/issues/133

@spencergibb As this issue was already solved in Spring Boot, I think it can be closed.
What do you think?

I'd like to hear from someone else if they can try snapshots of boot.

@yuanjinyong, @ikeyat, @indraneelb1903 or @jiang-wei?

As OriginTrackedMapPropertySource is a final class, it can not be extended by EncryptableMapPropertySourceWrapper, can change the code as following?

if (source instanceof OriginTrackedMapPropertySource 

to

if (source instanceof MapPropertySource 

@yuanjinyong, the change you suggested is what it was originally and it caused us problems. You can always delegate rather than extend.

@yuanjinyong, the change you suggested is what it was originally and it caused us problems. You can always delegate rather than extend.

originally is following:

if (source instanceof EnumerablePropertySource 

not:

if (source instanceof MapPropertySource
Was this page helpful?
0 / 5 - 0 ratings