Java Code Examples for org.springframework.boot.env.PropertySourceLoader#load()

The following examples show how to use org.springframework.boot.env.PropertySourceLoader#load() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConfigPrinter.java    From Qualitis with Apache License 2.0 6 votes vote down vote up
@PostConstruct
public void printConfig() throws UnSupportConfigFileSuffixException {
    LOGGER.info("Start to print config");
    addPropertiesFile();
    ResourceLoader resourceLoader = new DefaultResourceLoader();
    LOGGER.info("Prepared to print config in file: {}", propertiesFiles);

    for (String fileName : propertiesFiles) {
        LOGGER.info("======================== Config in {} ========================", fileName);
        PropertySourceLoader propertySourceLoader = getPropertySourceLoader(fileName);
        Resource resource = resourceLoader.getResource(fileName);
        try {
            List<PropertySource<?>> propertySources = propertySourceLoader.load(fileName, resource);
            for (PropertySource p : propertySources) {
                Map<String, Object> map = (Map<String, Object>) p.getSource();
                for (String key : map.keySet()) {
                    LOGGER.info("Name: [{}]=[{}]", key, map.get(key));
                }
            }
        } catch (IOException e) {
            LOGGER.info("Failed to open file: {}, caused by: {}, it does not matter", fileName, e.getMessage());
        }
        LOGGER.info("=======================================================================================\n");
    }
    LOGGER.info("Succeed to print all configs");
}
 
Example 2
Source File: ResourceLoadFactory.java    From mPaaS with Apache License 2.0 6 votes vote down vote up
@Override
public PropertySource<?> createPropertySource(String name, EncodedResource resource) throws IOException {
    PropertySource<?> propSource = null;
    String propName = name;
    if (StringUtils.isEmpty(propName)) {
        propName = getNameForResource(resource.getResource());
    }
    if (resource.getResource().exists()) {
        String fileName = resource.getResource().getFilename();
        for (PropertySourceLoader loader : loaders) {
            if (checkFileType(fileName, loader.getFileExtensions())) {
                List<PropertySource<?>> propertySources = loader.load(propName, resource.getResource());
                if (!propertySources.isEmpty()) {
                    propSource = propertySources.get(0);
                }
            }
        }
    } else {
        throw new FileNotFoundException(propName + "对应文件'" + resource.getResource().getFilename() + "'不存在");
    }
    return propSource;
}
 
Example 3
Source File: ResourceLoadFactory.java    From mPass with Apache License 2.0 6 votes vote down vote up
@Override
public PropertySource<?> createPropertySource(String name, EncodedResource resource) throws IOException {
    PropertySource<?> propSource = null;
    String propName = name;
    if (StringUtils.isEmpty(propName)) {
        propName = getNameForResource(resource.getResource());
    }
    if (resource.getResource().exists()) {
        String fileName = resource.getResource().getFilename();
        for (PropertySourceLoader loader : loaders) {
            if (checkFileType(fileName, loader.getFileExtensions())) {
                List<PropertySource<?>> propertySources = loader.load(propName, resource.getResource());
                if (!propertySources.isEmpty()) {
                    propSource = propertySources.get(0);
                }
            }
        }
    } else {
        throw new FileNotFoundException(propName + "对应文件'" + resource.getResource().getFilename() + "'不存在");
    }
    return propSource;
}
 
Example 4
Source File: FlowableDefaultPropertiesEnvironmentPostProcessor.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
void load(String location, PropertySourceLoader loader) {
    try {
        Resource resource = resourceLoader.getResource(location);
        if (!resource.exists()) {
            return;
        }
        String propertyResourceName = "flowableDefaultConfig: [" + location + "]";

        List<PropertySource<?>> propertySources = loader.load(propertyResourceName, resource);
        if (propertySources == null) {
            return;
        }
        propertySources.forEach(source -> environment.getPropertySources().addLast(source));
    } catch (Exception ex) {
        throw new IllegalStateException("Failed to load property "
            + "source from location '" + location + "'", ex);
    }
}
 
Example 5
Source File: EncryptablePropertySourceBeanFactoryPostProcessor.java    From jasypt-spring-boot with MIT License 4 votes vote down vote up
@SneakyThrows
private List<PropertySource<?>> load(PropertySourceLoader loader, String sourceName, Resource resource) {
    return loader.load(sourceName, resource);
}