Describe the bug Spring cloud version: 2021.0.1 When trying to include profiles with the spring.profiles.include property for the jdbc spring cloud config environment the profile is not included.

Sample I have the following properties table for the jdbc spring cloud config profile: |application|profile|label|key|value| |------------|-------|------|---|--| |application|myprofile|master|my-profile-variable|my-profile-value| |myapp|default|master|spring.profiles.include|myprofile|

Right now when I call the config service to fetch the config for myapp with /myapp/default I get the following reponse:

{
  "name": "myapp",
  "profiles": [
    "default"
  ],
  "label": null,
  "version": null,
  "state": null,
  "propertySources": [
    {
      "name": "myapp-default",
      "source": {
        "spring.profiles.include": "myprofile"
      }
    }
  ]
}

But I would expect to get the following:

{
  "name": "myapp",
  "profiles": [
    "default"
  ],
  "label": null,
  "version": null,
  "state": null,
  "propertySources": [
    {
      "name": "application-myprofile",
      "source": {
        "my-profile-property": "my-profile-value"
      }
    },
    {
      "name": "myapp-default",
      "source": {
        "spring.profiles.include": "myprofile"
      }
    }
  ]
}

This works well with the Git backend.

Comment From: ryanjbaxter

In the context of git, svn, or file based repositories we get this functionality via Boot's config data functionality which is loading the configuration files the same way Boot does.

In the JDBC case, and I imaging the same is true for the other environment repositories, we don't get all the benefits.

I am not sure if there is something we can do to handle all environment repositories, or if we need to address this in each environment repository.

Comment From: woshikid

I use Spring cloud version 2021.0.1 too, I can't reproduce this issue because include fails on Git backend too. It throws org.springframework.boot.context.config.InvalidConfigDataPropertyException: Property 'spring.profiles.include' imported from location xxxxx.

There's a check that forbid includes in InvalidConfigDataPropertyException

if (contributor.isFromProfileSpecificImport()
        && !contributor.hasConfigDataOption(ConfigData.Option.IGNORE_PROFILES)) {
    PROFILE_SPECIFIC_ERRORS.forEach((name) -> {
        ConfigurationProperty property = propertySource.getConfigurationProperty(name);
        if (property != null) {
            throw new InvalidConfigDataPropertyException(property, true, null, contributor.getResource());
        }
    });
}

the forbidden list in PROFILE_SPECIFIC_ERRORS above is [spring.profiles.include, spring.profiles.include[0], spring.profiles.active, spring.profiles.active[0], spring.profiles.default, spring.profiles.default[0]]

So if you try to include other profiles in config server, it throws exception.

Comment From: woshikid

But it's weird the JDBC backend didn't throw a exception and the include is not happened. I'll check this later.

Comment From: woshikid

MultipleJGitEnvironmentRepository and NativeEnvironmentRepository calls ConfigDataEnvironmentPostProcessor.applyTo() which calls ConfigDataEnvironmentPostProcessor.postProcessEnvironment() and throws exception in ConfigDataEnvironment.checkForInvalidProperties, which forbid profile includes.

But JdbcEnvironmentRepository don't call ConfigDataEnvironmentPostProcessor at all, so spring.profiles.include will not cause an exception and it was treated as a normal property.

Comment From: ryanjbaxter

This goes back to what I said above

In the context of git, svn, or file based repositories we get this functionality via Boot's config data functionality which is loading the configuration files the same way Boot does.

Comment From: woshikid

Yes, except it doesn't support 'include' feature.

Comment From: woshikid

This function is specifically disabled.