/** * 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); } }
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; } } } } }
/** * 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); } } }
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; }
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; }
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())); } }
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); }
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); }
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); }
@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); } }
@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); } }
@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); } }
@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); } }
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; } }
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; } }
@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(); }
@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); } } }
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); } }
/** * 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; }
/** * 获取指定的资源对象 * @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; }
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(); } } }
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.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); } } }
/** * 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; }
/** * 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()); } }
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; }
@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); }
/** * 获取配置文件 * * @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; }
public static void loadAllProperties(String propertyFileName) { try { Properties properties = PropertiesLoaderUtils.loadAllProperties(propertyFileName); processProperties(properties); } catch (IOException e) { e.printStackTrace(); } }