Java 类org.springframework.core.io.support.PropertiesLoaderUtils 实例源码

项目: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);
    }
}
项目:xproject    文件:GlobalPropertySources.java   
protected void loadProperties(Properties props) throws IOException {
    if (this.locations != null) {
        for (Resource location : this.locations) {
            logger.info("Loading properties file from " + location);
            try {
                PropertiesLoaderUtils.fillProperties(props,
                        new EncodedResource(location, this.fileEncoding));
            } catch (IOException ex) {
                if (this.ignoreResourceNotFound) {
                    logger.warn("Could not load properties from " + location + ": " + ex.getMessage());
                } else {
                    throw ex;
                }
            }
        }
    }
}
项目:lams    文件:KeyNamingStrategy.java   
/**
 * Merges the {@code Properties} configured in the {@code mappings} and
 * {@code mappingLocations} into the final {@code Properties} instance
 * used for {@code ObjectName} resolution.
 * @throws IOException
 */
@Override
public void afterPropertiesSet() throws IOException {
    this.mergedMappings = new Properties();

    CollectionUtils.mergePropertiesIntoMap(this.mappings, this.mergedMappings);

    if (this.mappingLocations != null) {
        for (int i = 0; i < this.mappingLocations.length; i++) {
            Resource location = this.mappingLocations[i];
            if (logger.isInfoEnabled()) {
                logger.info("Loading JMX object name mappings file from " + location);
            }
            PropertiesLoaderUtils.fillProperties(this.mergedMappings, location);
        }
    }
}
项目:bdf2    文件:SchedulerServiceImpl.java   
protected Scheduler newScheduler()throws SchedulerException{
    StdSchedulerFactory factory=new StdSchedulerFactory();
    Properties mergedProps = new Properties();
    mergedProps.setProperty(StdSchedulerFactory.PROP_THREAD_POOL_CLASS, SimpleThreadPool.class.getName());
    mergedProps.setProperty("org.quartz.scheduler.instanceName", "BDF2Scheduler");
    mergedProps.setProperty("org.quartz.scheduler.instanceId", "CoreBDF2Scheduler");
    mergedProps.setProperty("org.quartz.scheduler.makeSchedulerThreadDaemon", makeSchedulerThreadDaemon);
    mergedProps.setProperty("org.quartz.threadPool.threadCount", Integer.toString(threadCount));
    if (this.configLocation != null) {
        try {
            PropertiesLoaderUtils.fillProperties(mergedProps, this.configLocation);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    factory.initialize(mergedProps);
    Scheduler scheduler=factory.getScheduler();
    Collection<JobExecutionListener> jobListeners = this.getApplicationContext().getBeansOfType(JobExecutionListener.class).values();
    for(JobExecutionListener jobListener:jobListeners){
        jobListener.setSessionFactory(getSessionFactory());
        scheduler.getListenerManager().addJobListener(jobListener);
    }
    return scheduler;
}
项目:lodsve-framework    文件:ResourceBundleHolder.java   
private Properties getPropertiesFromFile(String baseName, Resource resource) {
    Properties properties = new Properties();

    String fileType = FileUtils.getFileExt(resource.getFilename());

    try {
        if (SUFFIX_OF_PROPERTIES.equals(fileType)) {
            //1.properties
            PropertiesLoaderUtils.fillProperties(properties, new EncodedResource(resource, "UTF-8"));
        } else if (SUFFIX_OF_TEXT.equals(fileType) || SUFFIX_OF_HTML.equals(fileType)) {
            //2.txt/html
            properties.put(baseName, ResourceUtils.getContent(resource));
        } else {
            //do nothing!
            logger.debug("this file '{}' is not properties, txt, html!", resource);
        }
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
        return null;
    }

    return properties;
}
项目:lodsve-framework    文件:ParamsHome.java   
private static void initExtResources() {
    String filePath = System.getProperty(EXT_PARAMS_FILE_NAME);
    if (StringUtils.isBlank(filePath)) {
        return;
    }

    System.out.println(String.format("获取到%s路径为'{%s}'!", EXT_PARAMS_FILE_NAME, filePath));

    Resource resource = new FileSystemResource(filePath);
    if (!resource.exists()) {
        System.err.println(String.format("找不到外部文件'[%s]'!", filePath));
        return;
    }

    try {
        PropertiesLoaderUtils.fillProperties(EXT_PARAMS_PROPERTIES, new EncodedResource(resource, "UTF-8"));
    } catch (IOException e) {
        e.printStackTrace();
        System.err.println(String.format("读取路径为'%s'的文件失败!失败原因是'%s'!", filePath, e.getMessage()));
    }
}
项目:lodsve-framework    文件:Log4JConfiguration.java   
public static void init() {
    Resource resource = new ClassPathResource("/META-INF/log4j.properties", Thread.currentThread().getContextClassLoader());

    if (!resource.exists()) {
        resource = Env.getFileEnv("log4j.properties");
    }

    if (resource == null || !resource.exists()) {
        throw new RuntimeException("配置文件'log4j.properties'找不到!");
    }

    Properties prop = null;
    try {
        prop = PropertiesLoaderUtils.loadProperties(resource);
    } catch (IOException e) {
        System.err.println("no log4j configuration file!");
    }

    PropertyConfigurator.configure(prop);
}
项目:spring4-understanding    文件:KeyNamingStrategy.java   
/**
 * Merges the {@code Properties} configured in the {@code mappings} and
 * {@code mappingLocations} into the final {@code Properties} instance
 * used for {@code ObjectName} resolution.
 * @throws IOException
 */
@Override
public void afterPropertiesSet() throws IOException {
    this.mergedMappings = new Properties();

    CollectionUtils.mergePropertiesIntoMap(this.mappings, this.mergedMappings);

    if (this.mappingLocations != null) {
        for (int i = 0; i < this.mappingLocations.length; i++) {
            Resource location = this.mappingLocations[i];
            if (logger.isInfoEnabled()) {
                logger.info("Loading JMX object name mappings file from " + location);
            }
            PropertiesLoaderUtils.fillProperties(this.mergedMappings, location);
        }
    }
}
项目:eSDK_EC_SDK_Java    文件:ConfigManagerNoDecrypt.java   
private void processConfigFile(Resource resource)
    throws IOException
{
    String absPath = null;
    if (null != resource.getURL() && !resource.getURL().getFile().contains("jar!"))
    {
        absPath = resource.getFile().getAbsolutePath();
    }
    LOGGER.info("Loading configuration file " + resource.getFilename() + " from " + absPath + "|" + resource);
    Properties props = PropertiesLoaderUtils.loadProperties(resource);
    ConfigFile configFile = new ConfigFile();
    configFile.setFileName(resource.getFilename());
    configFile.setFilePath(absPath);
    configFile.setConfigList(parseConfigFile(props));
    CONFIG_FILES.add(configFile);
}
项目:eSDK_EC_SDK_Java    文件:ConfigManagerUpdate.java   
private static void processConfigFile(Resource resource)
    throws IOException
{
    String absPath = null;
    if (null != resource.getURL() && !resource.getURL().getFile().contains("jar!"))
    {
        absPath = resource.getFile().getAbsolutePath();
    }
    LOGGER.info("Loading configuration file " + resource.getFilename() + " from " + absPath + "|" + resource);
    Properties props = PropertiesLoaderUtils.loadProperties(resource);
    ConfigFile configFile = new ConfigFile();
    configFile.setFileName(resource.getFilename());
    configFile.setFilePath(absPath);
    configFile.setConfigList(parseConfigFile(props));
    CONFIG_FILES.add(configFile);
}
项目:my-spring-cache-redis    文件:KeyNamingStrategy.java   
/**
 * Merges the {@code Properties} configured in the {@code mappings} and
 * {@code mappingLocations} into the final {@code Properties} instance
 * used for {@code ObjectName} resolution.
 * @throws IOException
 */
@Override
public void afterPropertiesSet() throws IOException {
    this.mergedMappings = new Properties();

    CollectionUtils.mergePropertiesIntoMap(this.mappings, this.mergedMappings);

    if (this.mappingLocations != null) {
        for (int i = 0; i < this.mappingLocations.length; i++) {
            Resource location = this.mappingLocations[i];
            if (logger.isInfoEnabled()) {
                logger.info("Loading JMX object name mappings file from " + location);
            }
            PropertiesLoaderUtils.fillProperties(this.mergedMappings, location);
        }
    }
}
项目:eSDK_IVS_Java    文件:ConfigManagerNoDecrypt.java   
private void processConfigFile(Resource resource)
    throws IOException
{
    String absPath = null;
    if (null != resource.getURL() && !resource.getURL().getFile().contains("jar!"))
    {
        absPath = resource.getFile().getAbsolutePath();
    }
    LOGGER.info("Loading configuration file " + resource.getFilename() + " from " + absPath + "|" + resource);
    Properties props = PropertiesLoaderUtils.loadProperties(resource);
    ConfigFile configFile = new ConfigFile();
    configFile.setFileName(resource.getFilename());
    configFile.setFilePath(absPath);
    configFile.setConfigList(parseConfigFile(props));
    CONFIG_FILES.add(configFile);
}
项目:eSDK_IVS_Java    文件:ConfigManagerUpdate.java   
private static void processConfigFile(Resource resource)
    throws IOException
{
    String absPath = null;
    if (null != resource.getURL() && !resource.getURL().getFile().contains("jar!"))
    {
        absPath = resource.getFile().getAbsolutePath();
    }
    LOGGER.info("Loading configuration file " + resource.getFilename() + " from " + absPath + "|" + resource);
    Properties props = PropertiesLoaderUtils.loadProperties(resource);
    ConfigFile configFile = new ConfigFile();
    configFile.setFileName(resource.getFilename());
    configFile.setFilePath(absPath);
    configFile.setConfigList(parseConfigFile(props));
    CONFIG_FILES.add(configFile);
}
项目:test    文件:NsTradeProvider.java   
@Override
public void getPropert() {
    try {
        Resource resource = new ClassPathResource(PROPERTY_NAME);
        Properties props = PropertiesLoaderUtils.loadProperties(resource);
        providerMap = Maps.newConcurrentMap();
        Provider provider = new Provider();
        provider.setHost(props.getProperty("ns_envPRDHost"));
        provider.setMarket(Integer.parseInt(props.getProperty("ns_market")));
        provider.setFirstKey(props.getProperty("ns_firstKey"));
        provider.setSecondKey(props.getProperty("ns_secondKey"));
        providerMap.put("provider", provider);
    } catch (Exception e) {
        throw new RuntimeException("读取配置文件出错!", e);
    }
}
项目:test    文件:NjTradeProvider.java   
@Override
public void getPropert() {
    try {
        Resource resource = new ClassPathResource(PROPERTY_NAME);
        Properties props = PropertiesLoaderUtils.loadProperties(resource);
        providerMap = Maps.newConcurrentMap();
        Provider provider = new Provider();
        provider.setHost(props.getProperty("nj_envPRDHost"));
        provider.setMarket(Integer.parseInt(props.getProperty("nj_market")));
        provider.setFirstKey(props.getProperty("nj_firstKey"));
        provider.setSecondKey(props.getProperty("nj_secondKey"));
        providerMap.put("provider", provider);
    } catch (Exception e) {
        throw new RuntimeException("读取配置文件出错!", e);
    }
}
项目:test    文件:Entrace.java   
@Override
public void getPropert() {
    try {
        Resource resource = new ClassPathResource(PROPERTY_NAME);
        Properties props = PropertiesLoaderUtils.loadProperties(resource);
        Provider provider = new Provider();
        provider.setHost(props.getProperty("host"));
        provider.setHostNext(props.getProperty("host_next"));
        provider.setHostUser(props.getProperty("host_user"));
        provider.setReferenceInformation(props.getProperty("reference_information"));
        provider.setHostConnect(props.getProperty("host_connect"));
        provider.setTelphone(props.getProperty("telphone"));
        provider.setBankType(props.getProperty("bank_type"));
        provider.setSection(props.getProperty("section"));
        providerMap.put("provider", provider);
    } catch (Exception e) {
        LOG.warn("An error occours when reading profiles", e);
    }
}
项目:test    文件:NsTradeProvider.java   
@Override
public void getPropert() {
    try {
        Resource resource = new ClassPathResource(PROPERTY_NAME);
        Properties props = PropertiesLoaderUtils.loadProperties(resource);
        providerMap = Maps.newConcurrentMap();
        Provider provider = new Provider();
        provider.setHost(props.getProperty("ns_envPRDHost"));
        provider.setMarket(Integer.parseInt(props.getProperty("ns_market")));
        provider.setFirstKey(props.getProperty("ns_firstKey"));
        provider.setSecondKey(props.getProperty("ns_secondKey"));
        providerMap.put("provider", provider);
    } catch (Exception e) {
        throw new RuntimeException("读取配置文件出错!", e);
    }
}
项目:test    文件:NjTradeProvider.java   
@Override
public void getPropert() {
    try {
        Resource resource = new ClassPathResource(PROPERTY_NAME);
        Properties props = PropertiesLoaderUtils.loadProperties(resource);
        providerMap = Maps.newConcurrentMap();
        Provider provider = new Provider();
        provider.setHost(props.getProperty("nj_envPRDHost"));
        provider.setMarket(Integer.parseInt(props.getProperty("nj_market")));
        provider.setFirstKey(props.getProperty("nj_firstKey"));
        provider.setSecondKey(props.getProperty("nj_secondKey"));
        providerMap.put("provider", provider);
    } catch (Exception e) {
        throw new RuntimeException("读取配置文件出错!", e);
    }
}
项目:test    文件:Entrace.java   
@Override
public void getPropert() {
    filter = new HashMap<String, String>();
    allMassage = new ArrayList<String>();
    try {
        Resource resource = new ClassPathResource(PROPERTY_NAME);
        Properties props = PropertiesLoaderUtils.loadProperties(resource);
        providerMap = Maps.newConcurrentMap();
        Provider provider = new Provider();
        provider.setHost(props.getProperty("host"));
        provider.setTurnPage(props.getProperty("turn_page"));
        provider.setBankType(props.getProperty("bank_type"));
        provider.setReferenceInformation(props.getProperty("reference_information"));
        provider.setThreadNum(props.getProperty("user_thread"));

        providerMap.put("provider", provider);
    } catch (Exception e) {
        LOG.warn("read profiles from yichen", e);
    }
}
项目:test    文件:Property.java   
public static String getUrl(String propertyName, String from, String to) {
    try {
        Resource resource = new ClassPathResource(propertyName);
        Properties props = PropertiesLoaderUtils.loadProperties(resource);
        String fetchUrl = "";
        if (from.contains("blog")) {
            fetchUrl = props.getProperty("blog_url");
        } else {
            fetchUrl = props.getProperty("notice_url");
        }
        from = "{" + from + "}";
        return StringUtils.replace(fetchUrl, from, to);
    } catch (Exception e) {
        return null;
    }
}
项目:test    文件:Property.java   
public static Object getOpenAccount(String propertyName, Object obj, String openAccountStr,
        String openAccountUrlStr) {
    try {
        Resource resource = new ClassPathResource(propertyName);
        Properties props = PropertiesLoaderUtils.loadProperties(resource);
        String openAccount = props.getProperty(openAccountStr);
        String openAccountUrl = props.getProperty(openAccountUrlStr);
        if (obj instanceof BlogModel) {
            BlogModel blogModel = (BlogModel) obj;
            blogModel.setOpenAccount(openAccount);
            blogModel.setOpenAccountUrl(openAccountUrl);
            return blogModel;
        } else {
            NoticeModel noticeModel = (NoticeModel) obj;
            noticeModel.setOpenAccount(openAccount);
            noticeModel.setOpenAccountUrl(openAccountUrl);
            return noticeModel;
        }
    } catch (Exception e) {
        return null;
    }
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:PropertiesConfigurationFactoryParameterizedTests.java   
@Deprecated
private Foo bindFoo(final String values) throws Exception {
    Properties properties = PropertiesLoaderUtils
            .loadProperties(new ByteArrayResource(values.getBytes()));
    if (this.usePropertySource) {
        MutablePropertySources propertySources = new MutablePropertySources();
        propertySources.addFirst(new PropertiesPropertySource("test", properties));
        this.factory.setPropertySources(propertySources);
    }
    else {
        this.factory.setProperties(properties);
    }

    this.factory.afterPropertiesSet();
    return this.factory.getObject();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:DevToolsHomePropertiesPostProcessor.java   
@Override
public void postProcessEnvironment(ConfigurableEnvironment environment,
        SpringApplication application) {
    File home = getHomeFolder();
    File propertyFile = (home == null ? null : new File(home, FILE_NAME));
    if (propertyFile != null && propertyFile.exists() && propertyFile.isFile()) {
        FileSystemResource resource = new FileSystemResource(propertyFile);
        Properties properties;
        try {
            properties = PropertiesLoaderUtils.loadProperties(resource);
            environment.getPropertySources().addFirst(
                    new PropertiesPropertySource("devtools-local", properties));
        }
        catch (IOException ex) {
            throw new IllegalStateException("Unable to load " + FILE_NAME, ex);
        }
    }
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:DevToolsSettings.java   
static DevToolsSettings load(String location) {
    try {
        DevToolsSettings settings = new DevToolsSettings();
        Enumeration<URL> urls = Thread.currentThread().getContextClassLoader()
                .getResources(location);
        while (urls.hasMoreElements()) {
            settings.add(PropertiesLoaderUtils
                    .loadProperties(new UrlResource(urls.nextElement())));
        }
        return settings;
    }
    catch (Exception ex) {
        throw new IllegalStateException("Unable to load devtools settings from "
                + "location [" + location + "]", ex);
    }
}
项目:adwords-alerting    文件:AwAlerting.java   
/**
 * Initialize the application context, adding the properties configuration file depending on the
 * specified path.
 *
 * @param propertiesResource the properties resource
 * @return the resource loaded from the properties file
 * @throws IOException error opening the properties file
 */
private static Properties initApplicationContextAndProperties(Resource propertiesResource)
    throws IOException {
  LOGGER.trace("Innitializing Spring application context.");
  DynamicPropertyPlaceholderConfigurer.setDynamicResource(propertiesResource);
  Properties properties = PropertiesLoaderUtils.loadProperties(propertiesResource);

  // Selecting the XMLs to choose the Spring Beans to load.
  List<String> listOfClassPathXml = new ArrayList<String>();
  listOfClassPathXml.add("classpath:aw-alerting-processor-beans.xml");

  appCtx = new ClassPathXmlApplicationContext(
      listOfClassPathXml.toArray(new String[listOfClassPathXml.size()]));

  return properties;
}
项目:spring    文件:KeyNamingStrategy.java   
/**
 * Merges the {@code Properties} configured in the {@code mappings} and
 * {@code mappingLocations} into the final {@code Properties} instance
 * used for {@code ObjectName} resolution.
 * @throws IOException
 */
@Override
public void afterPropertiesSet() throws IOException {
    this.mergedMappings = new Properties();

    CollectionUtils.mergePropertiesIntoMap(this.mappings, this.mergedMappings);

    if (this.mappingLocations != null) {
        for (int i = 0; i < this.mappingLocations.length; i++) {
            Resource location = this.mappingLocations[i];
            if (logger.isInfoEnabled()) {
                logger.info("Loading JMX object name mappings file from " + location);
            }
            PropertiesLoaderUtils.fillProperties(this.mergedMappings, location);
        }
    }
}
项目:sosoapi-base    文件:PropertiesUtils.java   
/**
 * 获取指定的资源对象
 * @param propertiesFilePath
 * @return
 */
public static Properties getProperties(String propertiesFilePath){
    Properties properties = null;
    try {
        logger.info("加载资源[" + propertiesFilePath + "] ...");

        properties = PropertiesLoaderUtils.loadProperties(new EncodedResource(new ClassPathResource(propertiesFilePath), "UTF-8"));
    } 
    catch (IOException e) {
        logger.error("加载资源[" + propertiesFilePath + "]失败");
        logger.error(e.getMessage());

        e.printStackTrace();
    }

    return properties;
}
项目:sosoapi-base    文件:ErrorCodePropertyConfigurer.java   
protected void build() {
    for (Resource location : this.locations) {
        if (location == null) {
            continue;
        }
        try {
            Properties prop = PropertiesLoaderUtils.loadProperties(new EncodedResource(location,"UTF-8"));
            for (Entry<Object, Object> entry : prop.entrySet()) {
                ErrorCodeTool.setProperty(entry.getKey().toString(), entry.getValue().toString());
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
项目:spring-boot-concourse    文件:PropertiesConfigurationFactoryParameterizedTests.java   
@Deprecated
private Foo bindFoo(final String values) throws Exception {
    Properties properties = PropertiesLoaderUtils
            .loadProperties(new ByteArrayResource(values.getBytes()));
    if (this.usePropertySource) {
        MutablePropertySources propertySources = new MutablePropertySources();
        propertySources.addFirst(new PropertiesPropertySource("test", properties));
        this.factory.setPropertySources(propertySources);
    }
    else {
        this.factory.setProperties(properties);
    }

    this.factory.afterPropertiesSet();
    return this.factory.getObject();
}
项目:spring-boot-concourse    文件:DevToolsHomePropertiesPostProcessor.java   
@Override
public void postProcessEnvironment(ConfigurableEnvironment environment,
        SpringApplication application) {
    File home = getHomeFolder();
    File propertyFile = (home == null ? null : new File(home, FILE_NAME));
    if (propertyFile != null && propertyFile.exists() && propertyFile.isFile()) {
        FileSystemResource resource = new FileSystemResource(propertyFile);
        Properties properties;
        try {
            properties = PropertiesLoaderUtils.loadProperties(resource);
            environment.getPropertySources().addFirst(
                    new PropertiesPropertySource("devtools-local", properties));
        }
        catch (IOException ex) {
            throw new IllegalStateException("Unable to load " + FILE_NAME, ex);
        }
    }
}
项目:spring-boot-concourse    文件:DevToolsSettings.java   
static DevToolsSettings load(String location) {
    try {
        DevToolsSettings settings = new DevToolsSettings();
        Enumeration<URL> urls = Thread.currentThread().getContextClassLoader()
                .getResources(location);
        while (urls.hasMoreElements()) {
            settings.add(PropertiesLoaderUtils
                    .loadProperties(new UrlResource(urls.nextElement())));
        }
        return settings;
    }
    catch (Exception ex) {
        throw new IllegalStateException("Unable to load devtools settings from "
                + "location [" + location + "]", ex);
    }
}
项目:dhis2-core    文件:DefaultDhisConfigurationProvider.java   
private Properties loadDhisConf()
    throws IllegalStateException
{
    try ( InputStream in = locationManager.getInputStream( CONF_FILENAME ) )
    {
        Properties conf = PropertiesLoaderUtils.loadProperties( new InputStreamResource( in ) );
        substituteEnvironmentVariables( conf );

        return conf;
    }
    catch ( LocationManagerException | IOException | SecurityException ex )
    {
        log.debug( String.format( "Could not load %s", CONF_FILENAME ), ex );

        throw new IllegalStateException( "Properties could not be loaded", ex );
    }
}
项目:configx    文件:ConfigContext.java   
/**
 * 从configx.properties文件读取属性
 */
private void loadProperties() {
    Resource configxClientProperties = new ClassPathResource("configx.properties");
    if (configxClientProperties.exists()) {
        try {
            Properties defaultProperties = PropertiesLoaderUtils.loadProperties(configxClientProperties);
            PropertySource<?> defaultPropertySource = new PropertiesPropertySource("configxClientProperties", defaultProperties);
            this.environment.getPropertySources().addLast(defaultPropertySource);
        } catch (IOException e) {
            logger.error("Failed to load configx.properties", e);
        }
    }
}
项目:lams    文件:VelocityEngineFactory.java   
/**
 * Prepare the VelocityEngine instance and return it.
 * @return the VelocityEngine instance
 * @throws IOException if the config file wasn't found
 * @throws VelocityException on Velocity initialization failure
 */
public VelocityEngine createVelocityEngine() throws IOException, VelocityException {
    VelocityEngine velocityEngine = newVelocityEngine();
    Map<String, Object> props = new HashMap<String, Object>();

    // Load config file if set.
    if (this.configLocation != null) {
        if (logger.isInfoEnabled()) {
            logger.info("Loading Velocity config from [" + this.configLocation + "]");
        }
        CollectionUtils.mergePropertiesIntoMap(PropertiesLoaderUtils.loadProperties(this.configLocation), props);
    }

    // Merge local properties if set.
    if (!this.velocityProperties.isEmpty()) {
        props.putAll(this.velocityProperties);
    }

    // Set a resource loader path, if required.
    if (this.resourceLoaderPath != null) {
        initVelocityResourceLoader(velocityEngine, this.resourceLoaderPath);
    }

    // Log via Commons Logging?
    if (this.overrideLogging) {
        velocityEngine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM, new CommonsLogLogChute());
    }

    // Apply properties to VelocityEngine.
    for (Map.Entry<String, Object> entry : props.entrySet()) {
        velocityEngine.setProperty(entry.getKey(), entry.getValue());
    }

    postProcessVelocityEngine(velocityEngine);

    // Perform actual initialization.
    velocityEngine.init();

    return velocityEngine;
}
项目:lams    文件:LocalPersistenceManagerFactoryBean.java   
/**
 * Initialize the PersistenceManagerFactory for the given location.
 * @throws IllegalArgumentException in case of illegal property values
 * @throws IOException if the properties could not be loaded from the given location
 * @throws JDOException in case of JDO initialization errors
 */
@Override
public void afterPropertiesSet() throws IllegalArgumentException, IOException, JDOException {
    if (this.persistenceManagerFactoryName != null) {
        if (this.configLocation != null || !this.jdoPropertyMap.isEmpty()) {
            throw new IllegalStateException("'configLocation'/'jdoProperties' not supported in " +
                    "combination with 'persistenceManagerFactoryName' - specify one or the other, not both");
        }
        if (logger.isInfoEnabled()) {
            logger.info("Building new JDO PersistenceManagerFactory for name '" +
                    this.persistenceManagerFactoryName + "'");
        }
        this.persistenceManagerFactory = newPersistenceManagerFactory(this.persistenceManagerFactoryName);
    }

    else {
        Map<String, Object> mergedProps = new HashMap<String, Object>();
        if (this.configLocation != null) {
            if (logger.isInfoEnabled()) {
                logger.info("Loading JDO config from [" + this.configLocation + "]");
            }
            CollectionUtils.mergePropertiesIntoMap(
                    PropertiesLoaderUtils.loadProperties(this.configLocation), mergedProps);
        }
        mergedProps.putAll(this.jdoPropertyMap);
        logger.info("Building new JDO PersistenceManagerFactory");
        this.persistenceManagerFactory = newPersistenceManagerFactory(mergedProps);
    }

    // Build default JdoDialect if none explicitly specified.
    if (this.jdoDialect == null) {
        this.jdoDialect = new DefaultJdoDialect(this.persistenceManagerFactory.getConnectionFactory());
    }
}
项目:stage-job    文件:PropertiesUtil.java   
public static String getString(String key) {
    Properties prop = null;
    try {
        Resource resource = new ClassPathResource(file_name);
        EncodedResource encodedResource = new EncodedResource(resource,"UTF-8");
        prop = PropertiesLoaderUtils.loadProperties(encodedResource);
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
    }
    if (prop!=null) {
        return prop.getProperty(key);
    }
    return null;
}
项目:spring-boot-starter-dao    文件:GeneratorMain.java   
@Override
public void run(String... args) throws Exception {
    Properties properties = PropertiesLoaderUtils.loadProperties(new ClassPathResource("generator.properties"));
    String nodeName = properties.getProperty("mybatis.nodeName", null);
    Assert.hasText(nodeName, "节点名不可以为空");
    MybatisNodeProperties node = this.getNodeBYName(nodeName);
    this.buildProperties(properties, node);

    Assert.hasText(properties.getProperty("package.model"), "mapper的model目录不可以为空,配置项 package.model");
    Assert.hasText(properties.getProperty("package.repo"), "mapper的接口目录不可以为空,配置项 package.repo");
    Assert.hasText(properties.getProperty("package.mapper"), "mapper的xml目录不可以为空,配置项 package.mapper");

    this.generate(properties);

}
项目:spring-velocity-adapter    文件:VelocityEngineFactory.java   
/**
 * Prepare the VelocityEngine instance and return it.
 * @return the VelocityEngine instance
 * @throws IOException if the config file wasn't found
 * @throws VelocityException on Velocity initialization failure
 */
public VelocityEngine createVelocityEngine() throws IOException, VelocityException {
    VelocityEngine velocityEngine = newVelocityEngine();
    Map<String, Object> props = new HashMap<String, Object>();

    // Load config file if set.
    if (this.configLocation != null) {
        if (logger.isInfoEnabled()) {
            logger.info("Loading Velocity config from [" + this.configLocation + "]");
        }
        CollectionUtils.mergePropertiesIntoMap(PropertiesLoaderUtils.loadProperties(this.configLocation), props);
    }

    // Merge local properties if set.
    if (!this.velocityProperties.isEmpty()) {
        props.putAll(this.velocityProperties);
    }

    // Set a resource loader path, if required.
    if (this.resourceLoaderPath != null) {
        initVelocityResourceLoader(velocityEngine, this.resourceLoaderPath);
    }

    // Log via Commons Logging?
    if (this.overrideLogging) {
        velocityEngine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM, new CommonsLogLogChute());
    }

    // Apply properties to VelocityEngine.
    for (Map.Entry<String, Object> entry : props.entrySet()) {
        velocityEngine.setProperty(entry.getKey(), entry.getValue());
    }

    postProcessVelocityEngine(velocityEngine);

    // Perform actual initialization.
    velocityEngine.init();

    return velocityEngine;
}
项目:xmanager    文件:MysqlGenerator.java   
/**
 * 获取配置文件
 *
 * @return 配置Props
 */
private static Properties getProperties() {
    // 读取配置文件
    Resource resource = new ClassPathResource("/config/application.properties");
    Properties props = new Properties();
    try {
        props = PropertiesLoaderUtils.loadProperties(resource);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return props;
}
项目:tulingchat    文件:PropertiesLoaderUtil.java   
public static void loadAllProperties(String propertyFileName) {
    try {
        Properties properties = PropertiesLoaderUtils.loadAllProperties(propertyFileName);
        processProperties(properties);
    } catch (IOException e) {
        e.printStackTrace();
    }
}