Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BaseConfig.Patch #2

Closed
wltony opened this issue May 1, 2018 · 1 comment
Closed

BaseConfig.Patch #2

wltony opened this issue May 1, 2018 · 1 comment

Comments

@wltony
Copy link

wltony commented May 1, 2018

``
diff --git a/src/main/java/xyz/redtorch/trader/base/BaseConfig.java b/src/main/java/xyz/redtorch/trader/base/BaseConfig.java
index 293ee63..e6da1f1 100644
--- a/src/main/java/xyz/redtorch/trader/base/BaseConfig.java
+++ b/src/main/java/xyz/redtorch/trader/base/BaseConfig.java
@@ -1,9 +1,13 @@
package xyz.redtorch.trader.base;

+import java.net.MalformedURLException;
+import java.net.URL;
+
import org.apache.commons.configuration2.CompositeConfiguration;
import org.apache.commons.configuration2.PropertiesConfiguration;
import org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder;
import org.apache.commons.configuration2.builder.fluent.Parameters;
+import org.apache.commons.configuration2.builder.fluent.PropertiesBuilderParameters;
import org.apache.commons.configuration2.convert.DefaultListDelimiterHandler;
import org.apache.commons.configuration2.ex.ConfigurationException;
import org.slf4j.Logger;
@@ -16,19 +20,56 @@
public static CompositeConfiguration rtConfig;
static {
rtConfig = new CompositeConfiguration();

  •    try {
    
  •    	FileBasedConfigurationBuilder<PropertiesConfiguration> builder =
    
  •    		    new FileBasedConfigurationBuilder<PropertiesConfiguration>(PropertiesConfiguration.class)
    
  •    		    .configure(new Parameters().properties()
    
  •    		        .setFileName("RtConfig.properties")
    
  •    		        .setThrowExceptionOnMissing(true)
    
  •    		        .setListDelimiterHandler(new DefaultListDelimiterHandler(';'))
    
  •    		        .setIncludesAllowed(false));
    
  •    		PropertiesConfiguration propertiesConfiguration = builder.getConfiguration();
    
  •    		rtConfig.addConfiguration(propertiesConfiguration);
    
  •    } catch (ConfigurationException e) {
    
  •    	log.error("配置文件RtConfig.properties加载失败",e);
    
  •    	throw new Error("配置文件RtConfig.properties加载失败");
    
  •    }
    
  •   PropertiesBuilderParameters params =  new Parameters().properties()   
    
  •    .setThrowExceptionOnMissing(true)
    
  •    .setListDelimiterHandler(new DefaultListDelimiterHandler(';'))
    
  •    .setIncludesAllowed(false);
    
  •   if(!tryConfig(params,"file:./config/RtConfig.properties"))
    
  •   {
    
  •   	if(!tryConfig(params,"file:./RtConfig.properties"))
    
  •   	{
    
  •   		if(!tryConfig(params,"classpath:/config/RtConfig.properties"))
    
  •   		{
    
  •   			if(!tryConfig(params,"classpath:/RtConfig.properties"))
    
  •   			{
    
  •   				log.error("配置文件RtConfig.properties加载失败");
    
  •   	        	throw new Error("配置文件RtConfig.properties加载失败");
    
  •   			}
    
  •   		}
    
  •   	}
    
  •   }
    
  • }
  • static boolean tryConfig(PropertiesBuilderParameters params,String config_url_txt)
  • {
  •    try {
    
  •   	 URL configFileUrl = new URL(config_url_txt);
    
  •       FileBasedConfigurationBuilder<PropertiesConfiguration> builder =
    
  •       		    new FileBasedConfigurationBuilder<PropertiesConfiguration>(PropertiesConfiguration.class)
    
  •       		    .configure(params.setURL(configFileUrl));
    
  •       PropertiesConfiguration propertiesConfiguration = builder.getConfiguration();
    
  •       		rtConfig.addConfiguration(propertiesConfiguration);
    
  •       return true;
    
  •       } catch (ConfigurationException e) {
    
  •       	log.debug("配置文件RtConfig.properties加载失败",e);
    
  •       	return false;
    
  •       }catch (MalformedURLException e)
    
  •    	{
    
  •       	log.debug("配置文件RtConfig.properties加载失败",e);
    
  •       	return false;
    
  •    	}
    
    }
    }
@sun0x00
Copy link
Owner

sun0x00 commented May 3, 2018

感谢提供代码支持,为了增强兼容性,会对上述代码修改后并入

@sun0x00 sun0x00 closed this as completed in ebbc4e0 May 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants