作者 申海龙

修改 代码中的reids 写到配置文件中

1 -package com.agent.util;  
2 -  
3 -import com.framework.util.PropertiesLoader;  
4 -import org.slf4j.Logger;  
5 -import org.slf4j.LoggerFactory;  
6 -  
7 -import java.io.InputStream;  
8 -import java.util.Properties;  
9 -  
10 -/**  
11 - * @Auther: shenhl  
12 - * @Date: 2019/3/6 15:22  
13 - */  
14 -public class RedisUtils {  
15 -  
16 -  
17 - private static final Logger logger = LoggerFactory.getLogger(RedisUtils.class);  
18 -  
19 - private static final String CONFIG_FILE = "/config.properties";  
20 -  
21 - /**  
22 - * 配置文件properties获取value  
23 - * @param key  
24 - * @param propertyFile 注意classpath下文件以"/"开始  
25 - * @return  
26 - */  
27 - public static String get(String key){  
28 - Properties properties = loadProperty("/redis.properties");  
29 - return (String) properties.get(key);  
30 - }  
31 -  
32 -  
33 - /**  
34 - * load properties文件  
35 - * @param propertyFile  
36 - * @return  
37 - */  
38 - public static Properties loadProperty(String propertyFile){  
39 - InputStream in=PropertiesLoader.class.getResourceAsStream(propertyFile);  
40 - Properties properties = new Properties();  
41 - try{  
42 - properties.load(in);  
43 - }catch(Exception e){  
44 - logger.error("解析文件失败:文件名={}", propertyFile, e);  
45 - }  
46 - return properties;  
47 - }  
48 -  
49 -  
50 - public static String getConfig(String key) {  
51 - Properties properties = PropertiesLoader.loadProperty(CONFIG_FILE);  
52 - return properties.getProperty(key);  
53 - }  
54 -  
55 -  
56 - public static String get(String key,String propertyFile){  
57 - Properties properties = loadProperty(propertyFile);  
58 - return (String) properties.get(key);  
59 - }  
60 -  
61 -  
62 -  
63 -}  
1 package com.agent.xml; 1 package com.agent.xml;
2 2
  3 +import com.framework.util.PropertiesLoader;
3 import org.apache.commons.lang3.StringUtils; 4 import org.apache.commons.lang3.StringUtils;
4 5
5 import redis.clients.jedis.Jedis; 6 import redis.clients.jedis.Jedis;
@@ -18,7 +19,11 @@ import redis.clients.jedis.Jedis; @@ -18,7 +19,11 @@ import redis.clients.jedis.Jedis;
18 class XmlSendTask extends Thread { 19 class XmlSendTask extends Thread {
19 // 创建 缓存服务器的地址ip 20 // 创建 缓存服务器的地址ip
20 // private Jedis jedis = new Jedis("10.50.3.71", 6379); 21 // private Jedis jedis = new Jedis("10.50.3.71", 6379);
21 - private Jedis jedis = new Jedis("10.50.3.84", 6379); 22 +
  23 +// private Jedis jedis = new Jedis("10.50.3.84", 6379);
  24 +
  25 + private Jedis jedis = new Jedis(PropertiesLoader.getRedis("host"),
  26 + Integer.valueOf(PropertiesLoader.getRedis("port")));
22 27
23 private String xml; 28 private String xml;
24 29
@@ -21,6 +21,8 @@ public class PropertiesLoader { @@ -21,6 +21,8 @@ public class PropertiesLoader {
21 21
22 private static final String CONFIG_FILE = "/config.properties"; 22 private static final String CONFIG_FILE = "/config.properties";
23 23
  24 + private static final String REDIS_FILE = "/redis.properties";
  25 +
24 /** 26 /**
25 * 配置文件properties获取value 27 * 配置文件properties获取value
26 * @param key 28 * @param key
@@ -55,6 +57,11 @@ public class PropertiesLoader { @@ -55,6 +57,11 @@ public class PropertiesLoader {
55 return properties.getProperty(key); 57 return properties.getProperty(key);
56 } 58 }
57 59
  60 + public static String getRedis(String key) {
  61 + Properties properties = PropertiesLoader.loadProperty(REDIS_FILE);
  62 + return properties.getProperty(key);
  63 + }
  64 +
58 65
59 public static String get(String key,String propertyFile){ 66 public static String get(String key,String propertyFile){
60 Properties properties = loadProperty(propertyFile); 67 Properties properties = loadProperty(propertyFile);