Affects: v5.2.6.RELEASE

I would like to be able to debug and log out where properties come from. This becomes needed if you are using Spring Boot with multiple microservices sharing configuration files but each having their own configuration file. It becomes hard to determine where a property is being set and why the one you intended on being effective is not.

Could we get origin information added to PropertyResolver interface. This could be added by adding a function like Origin getPropertyOrigin(String). The default implementation may just be to return the an Origin that just contains a string with the class name of the resolver but ideally it would return something like what org.springframework.boot.origin.OriginLookup returns. Looking at the packages it looks like Spring Boot layers origin information onto the Spring Framework Environment framework but would like this to be available instanceof casts.

For example this is how I emulate this behavior now:

        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;
    }

Comment From: spencergibb

Origin is from spring boot, so just keep the boot issue open.

Comment From: bclozel

Closing as a duplicate of https://github.com/spring-projects/spring-boot/issues/21613 - The origin support is in Spring Boot.

Comment From: ddcruver

I am glad to see that while they (spring boot team) have not committed to doing it, they are keeping it on the table. But in general I believe it would be nice for Spring Framework in general incorporate the Origin traceability into the Environment object at the framework level. While I know Spring Boot is a first-class spring project it would be nice to see this functionality supported across the board.