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

org.apereo.cas.MongoDbPropertySourceLocator Maven / Gradle / Ivy

The newest version!
package org.apereo.cas;

import lombok.RequiredArgsConstructor;
import lombok.val;
import org.springframework.cloud.bootstrap.config.PropertySourceLocator;
import org.springframework.core.env.CompositePropertySource;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;
import org.springframework.core.env.PropertySource;
import org.springframework.data.mongodb.core.MongoOperations;

/**
 * This is {@link MongoDbPropertySourceLocator}.
 *
 * @author Misagh Moayyed
 * @since 5.0.0
 */
@RequiredArgsConstructor
public class MongoDbPropertySourceLocator implements PropertySourceLocator {
    private final MongoOperations mongo;

    @Override
    public PropertySource locate(final Environment environment) {
        if (environment instanceof ConfigurableEnvironment) {
            val sourceName = MongoDbPropertySource.class.getSimpleName();
            val composite = new CompositePropertySource(sourceName);
            val source = new MongoDbPropertySource(sourceName, mongo);
            composite.addFirstPropertySource(source);
            return composite;
        }
        return null;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy