Java Code Examples for org.springframework.core.io.support.PropertiesLoaderUtils#loadAllProperties()

The following examples show how to use org.springframework.core.io.support.PropertiesLoaderUtils#loadAllProperties() . 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: DLockGenerator.java    From dlock with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example 2
Source File: PluggableSchemaResolver.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example 3
Source File: PluggableSchemaResolver.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example 4
Source File: DefaultNamespaceHandlerResolver.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example 5
Source File: SystemProps.java    From MultimediaDesktop with Apache License 2.0 5 votes vote down vote up
public static boolean InitProps() {
	try {
		props = PropertiesLoaderUtils.loadAllProperties(SERVER_FILE);
	} catch (IOException e) {
		log.fatal("读取配置文件失败", e);
		return false;
	}
	return props != null;
}
 
Example 6
Source File: DynamicConfig.java    From micro-service with MIT License 5 votes vote down vote up
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;
}
 
Example 7
Source File: BusEntityResolver.java    From cxf with Apache License 2.0 5 votes vote down vote up
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
    }
}
 
Example 8
Source File: VersionService.java    From airsonic-advanced with GNU General Public License v3.0 4 votes vote down vote up
public VersionService() throws IOException {
    build = PropertiesLoaderUtils.loadAllProperties("build.properties");
}