All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.elsci.springutils.PropertySourcesFactoryBean Maven / Gradle / Ivy

There is a newer version: 20231025.1145-36
Show newest version
package io.elsci.springutils;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertySource;
import org.springframework.core.env.PropertySources;

/**
 * As opposed to Spring's {@link MutablePropertySources} accepts an array in the constructor - therefore can be
 * defined in the XML.
 */
public class PropertySourcesFactoryBean implements FactoryBean {
    private final PropertySource[] propertySources;

    /**
     *
     * @param propertySources the first one has the highest priority, the last one has the lowest
     */
    public PropertySourcesFactoryBean(PropertySource[] propertySources) {
        this.propertySources = propertySources;
    }

    @Override
    public PropertySources getObject() {
        MutablePropertySources result = new MutablePropertySources();
        for (PropertySource propSource : propertySources)
            // because of the idiotic implementation of MutablePropertySources, adding it last, because
            // eventually it will added into another MutablePropertySources that would reverse them again
            result.addLast(propSource);
        return result;
    }

    @Override
    public Class getObjectType() {
        return PropertySources.class;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy