當前位置: 首頁>>代碼示例>>Java>>正文


Java PropertySourceLoader類代碼示例

本文整理匯總了Java中org.springframework.boot.env.PropertySourceLoader的典型用法代碼示例。如果您正苦於以下問題:Java PropertySourceLoader類的具體用法?Java PropertySourceLoader怎麽用?Java PropertySourceLoader使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


PropertySourceLoader類屬於org.springframework.boot.env包,在下文中一共展示了PropertySourceLoader類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createPropertySource

import org.springframework.boot.env.PropertySourceLoader; //導入依賴的package包/類
private PropertySource createPropertySource(AnnotationAttributes attributes, ConfigurableEnvironment environment, ResourceLoader resourceLoader, EncryptablePropertyResolver resolver, List<PropertySourceLoader> loaders) throws Exception {
    String name = generateName(attributes.getString("name"));
    String[] locations = attributes.getStringArray("value");
    boolean ignoreResourceNotFound = attributes.getBoolean("ignoreResourceNotFound");
    CompositePropertySource compositePropertySource = new CompositePropertySource(name);
    Assert.isTrue(locations.length > 0, "At least one @PropertySource(value) location is required");
    for (String location : locations) {
        String resolvedLocation = environment.resolveRequiredPlaceholders(location);
        Resource resource = resourceLoader.getResource(resolvedLocation);
        if (!resource.exists()) {
            if (!ignoreResourceNotFound) {
                throw new IllegalStateException(String.format("Encryptable Property Source '%s' from location: %s Not Found", name, resolvedLocation));
            } else {
                log.info("Ignoring NOT FOUND Encryptable Property Source '{}' from locations: {}", name, resolvedLocation);
            }
        } else {
            String actualName = name + "#" + resolvedLocation;
            loadPropertySource(loaders, resource, actualName)
                    .ifPresent(compositePropertySource::addPropertySource);
        }
    }
    return new EncryptableEnumerablePropertySourceWrapper<>(compositePropertySource, resolver);
}
 
開發者ID:ulisesbocchio,項目名稱:jasypt-spring-boot,代碼行數:24,代碼來源:EncryptablePropertySourceBeanFactoryPostProcessor.java

示例2: postProcessBeanFactory

import org.springframework.boot.env.PropertySourceLoader; //導入依賴的package包/類
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    ResourceLoader ac = new DefaultResourceLoader();
    MutablePropertySources propertySources = env.getPropertySources();
    Stream<AnnotationAttributes> encryptablePropertySourcesMetadata = getEncryptablePropertySourcesMetadata(beanFactory);
    EncryptablePropertyResolver propertyResolver = beanFactory.getBean(RESOLVER_BEAN_NAME, EncryptablePropertyResolver.class);
    List<PropertySourceLoader> loaders = initPropertyLoaders();
    encryptablePropertySourcesMetadata.forEach(eps -> loadEncryptablePropertySource(eps, env, ac, propertyResolver, propertySources, loaders));
}
 
開發者ID:ulisesbocchio,項目名稱:jasypt-spring-boot,代碼行數:10,代碼來源:EncryptablePropertySourceBeanFactoryPostProcessor.java

示例3: loadEncryptablePropertySource

import org.springframework.boot.env.PropertySourceLoader; //導入依賴的package包/類
private void loadEncryptablePropertySource(AnnotationAttributes encryptablePropertySource, ConfigurableEnvironment env, ResourceLoader resourceLoader, EncryptablePropertyResolver resolver, MutablePropertySources propertySources, List<PropertySourceLoader> loaders) throws BeansException {
    try {
        PropertySource ps = createPropertySource(encryptablePropertySource, env, resourceLoader, resolver, loaders);
        propertySources.addLast(ps);
        log.info("Created Encryptable Property Source '{}' from locations: {}", ps.getName(), Arrays.asList(encryptablePropertySource.getStringArray("value")));
    } catch (Exception e) {
        throw new ApplicationContextException("Exception Creating PropertySource", e);
    }
}
 
開發者ID:ulisesbocchio,項目名稱:jasypt-spring-boot,代碼行數:10,代碼來源:EncryptablePropertySourceBeanFactoryPostProcessor.java

示例4: loadPropertySource

import org.springframework.boot.env.PropertySourceLoader; //導入依賴的package包/類
private Optional<PropertySource<?>> loadPropertySource(List<PropertySourceLoader> loaders, Resource resource, String sourceName) throws IOException {
    return Optional.of(resource)
            .filter(this::isFile)
            .map(res -> loaders.stream()
                    .filter(loader -> canLoadFileExtension(loader, resource))
                    .findFirst()
                    .map(loader -> load(loader, sourceName, resource))
                    .orElse(null));
}
 
開發者ID:ulisesbocchio,項目名稱:jasypt-spring-boot,代碼行數:10,代碼來源:EncryptablePropertySourceBeanFactoryPostProcessor.java

示例5: loadProperties

import org.springframework.boot.env.PropertySourceLoader; //導入依賴的package包/類
private EnumerablePropertySource loadProperties(PropertySourceLoader hoconLoader, String path) throws IOException {
    return (EnumerablePropertySource) hoconLoader.load("hocon", new ClassPathResource(path), null);
}
 
開發者ID:zeldigas,項目名稱:spring-hocon-property-source,代碼行數:4,代碼來源:HoconPropertySourceLoaderTest.java

示例6: initPropertyLoaders

import org.springframework.boot.env.PropertySourceLoader; //導入依賴的package包/類
private List<PropertySourceLoader> initPropertyLoaders() {
    return SpringFactoriesLoader.loadFactories(PropertySourceLoader.class, getClass().getClassLoader());
}
 
開發者ID:ulisesbocchio,項目名稱:jasypt-spring-boot,代碼行數:4,代碼來源:EncryptablePropertySourceBeanFactoryPostProcessor.java

示例7: load

import org.springframework.boot.env.PropertySourceLoader; //導入依賴的package包/類
@SneakyThrows
private PropertySource<?> load(PropertySourceLoader loader, String sourceName, Resource resource) {
    return loader.load(sourceName, resource, null);
}
 
開發者ID:ulisesbocchio,項目名稱:jasypt-spring-boot,代碼行數:5,代碼來源:EncryptablePropertySourceBeanFactoryPostProcessor.java

示例8: canLoadFileExtension

import org.springframework.boot.env.PropertySourceLoader; //導入依賴的package包/類
private boolean canLoadFileExtension(PropertySourceLoader loader, Resource resource) {
    return Arrays.stream(loader.getFileExtensions())
            .anyMatch(extension -> resource.getFilename().toLowerCase().endsWith("." + extension.toLowerCase()));
}
 
開發者ID:ulisesbocchio,項目名稱:jasypt-spring-boot,代碼行數:5,代碼來源:EncryptablePropertySourceBeanFactoryPostProcessor.java


注:本文中的org.springframework.boot.env.PropertySourceLoader類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。