Skip to content

Property my-settings.networkName cannot be overriden with an environment variable for binding to an @PropertyConfiguration #2495

Closed
@uTestMichaelL

Description

@uTestMichaelL

I have a class like this:


@ConfigurationProperties(prefix = "my-settings")
public class Settings
{
     private String networkName;
     public void setNetworkName(String networkName) {this.networkName = networkName}
}

There is no way to bind an environment variable to networkName. Environment variables cannot have dots or slashes. I tried with MY_SETTINGS_NETWORK_NAME and MYSETTINGSNETWORKNAME and neither works.

I believe I traced the reason to the fact that I have a dot and a slash in the prefix+name, which is "my-settings.networkName"

When I put this into new RelaxedPropeties("my-settings.networkName") I get these:

my-settings.networkName
my_settings.networkName
my-settings_networkName
my-settings.network_name
my-settings.network-name
mySettingsNetworkName
mySettingsNetworkname
my-settings.networkname
my_settings.networkname
my-settings_networkname
mysettingsnetworkname
MY-SETTINGS.NETWORKNAME
MY_SETTINGS.NETWORKNAME
MY-SETTINGS_NETWORKNAME
MY-SETTINGS.NETWORK_NAME
MY-SETTINGS.NETWORK-NAME
MYSETTINGSNETWORKNAME

none of these are MY_SETTINGS_NETWORK_NAME, so that's the first problem. I need the HYPHEN_TO_UNDERSCORE and PERIOD_TO_UNDERSCORE manipulations to both get applied, or a new HYPHEN_AND_PERIOD_TO_UNDERSCORE manipulation created. I can probably do this in a pull request.

The second problem, and the reason MYSETTINGSNETWORKNAME environment variable doesn't work, is that RelaxedDataBinder.getPropertyValuesForNamePrefix() has this line:
if (name.startsWith(candidate)) {
and the candidates are fetched by doing new RelaxedNames(this.prefix) and this.prefix is "my-settings." - it also has both the dash and the dot, and the resulting candidates are:

my-settings.
my_settings.
my-settings_
mySettings.
mysettings.
MY-SETTINGS.
MY_SETTINGS.
MY-SETTINGS_
MYSETTINGS.

none of these are just "MYSETTINGS"

I am not sure what would be the best way to fix this part of it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions