Skip to content

Add Property origin information to environment #21613

@ddcruver

Description

@ddcruver

I already posted an feature request to Spring Framework but it might involve more trouble than it is worth to them. spring-projects/spring-framework#25157

Regardless short of that becoming available could Spring Boot implement an Environment interface that exposes the Origin and OriginLookup functionality.

For example instead of this:

private String getPropertySourceName(String property, Environment environment) {
    String propertySourceName = "";
     if (environment instanceof AbstractEnvironment) {
          MutablePropertySources propertySources = ((AbstractEnvironment) environment).getPropertySources();
          for (PropertySource<?> propertySource : propertySources) {
               Object propertyValue = propertySource.getProperty(property);
               if (propertyValue != null) {
                    if (propertySource instanceof OriginLookup) {
                         Origin origin = ((OriginLookup) propertySource).getOrigin(property);
                         propertySourceName = origin.toString();
                    } 
                    else {
                         propertySourceName = propertySource.getName();
                    }
                    break;
               }
          }
     }
     return propertySourceName;
}

I would like to do this:

private String getPropertySourceName(String property, Environment environment) {
     if (environment instanceof OriginTrackedEnvironment) {
          OriginTrackedEnvironment originTrackedEnvironment = ((OriginTrackedEnvironment) environment);
          return originTrackedEnvironment.getOrigin(property).toString();
     } 
     else {
          return "Unknown Origin";
     }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions