org.springframework.core.io.support.PropertiesLoaderUtils#loadAllProperties ( )源码实例Demo

下面列出了org.springframework.core.io.support.PropertiesLoaderUtils#loadAllProperties ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: dlock   文件: DLockGenerator.java
/**
 * Load the lease config from properties, and init the lockConfigMap.
 */
@PostConstruct
public void init() {
    try {
        // Using default path if no specified
        confPath = StringUtils.isBlank(confPath) ? DEFAULT_CONF_PATH : confPath;

        // Load lock config from properties
        Properties properties = PropertiesLoaderUtils.loadAllProperties(confPath);

        // Build the lockConfigMap
        for (Entry<Object, Object> propEntry : properties.entrySet()) {
            DLockType lockType = EnumUtils.valueOf(DLockType.class, propEntry.getKey().toString());
            Integer lease = Integer.valueOf(propEntry.getValue().toString());

            if (lockType != null && lease != null) {
                lockConfigMap.put(lockType, lease);
            }
        }

    } catch (Exception e) {
        throw new RuntimeException("Load distributed lock config fail", e);
    }
}
 
/**
 * Load the specified schema mappings lazily.
 */
private Map<String, String> getSchemaMappings() {
	Map<String, String> schemaMappings = this.schemaMappings;
	if (schemaMappings == null) {
		synchronized (this) {
			schemaMappings = this.schemaMappings;
			if (schemaMappings == null) {
				if (logger.isTraceEnabled()) {
					logger.trace("Loading schema mappings from [" + this.schemaMappingsLocation + "]");
				}
				try {
					Properties mappings =
							PropertiesLoaderUtils.loadAllProperties(this.schemaMappingsLocation, this.classLoader);
					if (logger.isTraceEnabled()) {
						logger.trace("Loaded schema mappings: " + mappings);
					}
					schemaMappings = new ConcurrentHashMap<>(mappings.size());
					CollectionUtils.mergePropertiesIntoMap(mappings, schemaMappings);
					this.schemaMappings = schemaMappings;
				}
				catch (IOException ex) {
					throw new IllegalStateException(
							"Unable to load schema mappings from location [" + this.schemaMappingsLocation + "]", ex);
				}
			}
		}
	}
	return schemaMappings;
}
 
/**
 * Load the specified schema mappings lazily.
 */
private Map<String, String> getSchemaMappings() {
	Map<String, String> schemaMappings = this.schemaMappings;
	if (schemaMappings == null) {
		synchronized (this) {
			schemaMappings = this.schemaMappings;
			if (schemaMappings == null) {
				if (logger.isTraceEnabled()) {
					logger.trace("Loading schema mappings from [" + this.schemaMappingsLocation + "]");
				}
				try {
					Properties mappings =
							PropertiesLoaderUtils.loadAllProperties(this.schemaMappingsLocation, this.classLoader);
					if (logger.isTraceEnabled()) {
						logger.trace("Loaded schema mappings: " + mappings);
					}
					schemaMappings = new ConcurrentHashMap<>(mappings.size());
					CollectionUtils.mergePropertiesIntoMap(mappings, schemaMappings);
					this.schemaMappings = schemaMappings;
				}
				catch (IOException ex) {
					throw new IllegalStateException(
							"Unable to load schema mappings from location [" + this.schemaMappingsLocation + "]", ex);
				}
			}
		}
	}
	return schemaMappings;
}
 
/**
 * Load the specified NamespaceHandler mappings lazily.
 */
private Map<String, Object> getHandlerMappings() {
	Map<String, Object> handlerMappings = this.handlerMappings;
	if (handlerMappings == null) {
		synchronized (this) {
			handlerMappings = this.handlerMappings;
			if (handlerMappings == null) {
				if (logger.isTraceEnabled()) {
					logger.trace("Loading NamespaceHandler mappings from [" + this.handlerMappingsLocation + "]");
				}
				try {
					Properties mappings =
							PropertiesLoaderUtils.loadAllProperties(this.handlerMappingsLocation, this.classLoader);
					if (logger.isTraceEnabled()) {
						logger.trace("Loaded NamespaceHandler mappings: " + mappings);
					}
					handlerMappings = new ConcurrentHashMap<>(mappings.size());
					CollectionUtils.mergePropertiesIntoMap(mappings, handlerMappings);
					this.handlerMappings = handlerMappings;
				}
				catch (IOException ex) {
					throw new IllegalStateException(
							"Unable to load NamespaceHandler mappings from location [" + this.handlerMappingsLocation + "]", ex);
				}
			}
		}
	}
	return handlerMappings;
}
 
源代码5 项目: MultimediaDesktop   文件: SystemProps.java
public static boolean InitProps() {
	try {
		props = PropertiesLoaderUtils.loadAllProperties(SERVER_FILE);
	} catch (IOException e) {
		log.fatal("读取配置文件失败", e);
		return false;
	}
	return props != null;
}
 
源代码6 项目: micro-service   文件: DynamicConfig.java
private static Map<String, Object> dynamicLoadProperties() {
	
	try {
		Properties properties = PropertiesLoaderUtils.loadAllProperties("application.properties");
		
		map.put("person.register.pre.day", Integer.parseInt(properties.getProperty("person.register.pre.day")));
		map.put("person.register.total", Integer.parseInt(properties.getProperty("person.register.total")));
		
		logger.info("load Properties result: {}", map);
	} catch (IOException e) {
		logger.error("load Properties error, {}", e.getMessage());
	}
	
	return map;
}
 
源代码7 项目: cxf   文件: BusEntityResolver.java
public BusEntityResolver(ClassLoader loader, EntityResolver dr, EntityResolver sr) {
    super(dr, sr);
    classLoader = loader;
    dtdResolver = dr;
    schemaResolver = sr;

    try {
        Properties mappings = PropertiesLoaderUtils.loadAllProperties("META-INF/spring.schemas",
                                                                      classLoader);
        schemaMappings = new ConcurrentHashMap<>(mappings.size());
        CollectionUtils.mergePropertiesIntoMap(mappings, schemaMappings);
    } catch (IOException e) {
        //ignore
    }
}
 
源代码8 项目: airsonic-advanced   文件: VersionService.java
public VersionService() throws IOException {
    build = PropertiesLoaderUtils.loadAllProperties("build.properties");
}