I already posted an feature request to Spring Framework but it might involve more trouble than it is worth to them. https://github.com/spring-projects/spring-framework/issues/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";
     }
}

Comment From: philwebb

We recently had a performance issue where we thought we might need to add our own Environment implementation. If we had done that, then this would be a nice addition to that class. As it stands, I'm not sure I want to add a custom Environment subclass just to support this.

We're planning to look at some configuration items in Spring Boot 2.4 so I'll leave this one open for now in case we end up adding an ApplicationEnvironment as part of that work.

Comment From: snicoll

We do have an ApplicationEnvironment now so I wonder if it's still on-hold?