Commit 3840b47d authored by 陈红帅's avatar 陈红帅

fix(admin):修改打包之后无法启动的bug

parent 1ba55fd9
......@@ -21,33 +21,23 @@ public class XxlJobAdminApplication {
}
private static void init(String[] args){
// 促使化zookeeper客户端工具类
// 初始化zookeeper客户端工具类
if(args == null || args.length == 0){
throw new RuntimeException("请传入zookeeper的地址");
}
ZookeeperClientUtil.init(args[0], "/weixt/conf");
// 创建zookeeper客户端
ZookeeperClientUtil configurationClient = new ZookeeperClientUtil();
try {
String resource = XxlJobAdminApplication.class.getResource("/application.properties").getPath();
Properties properties = new Properties();
properties.load(new FileInputStream(resource));
makeProperties(properties,configurationClient,"spring.datasource.url");
makeProperties(properties,configurationClient,"spring.datasource.username");
makeProperties(properties,configurationClient,"spring.datasource.password");
FileOutputStream fileOutputStream = new FileOutputStream(resource);
properties.store(fileOutputStream,"");
fileOutputStream.close();
}catch (Exception e){
e.printStackTrace();
}
setSystemPropertie(configurationClient,"spring.datasource.url");
setSystemPropertie(configurationClient,"spring.datasource.username");
setSystemPropertie(configurationClient,"spring.datasource.password");
}
private static void makeProperties(Properties properties, ZookeeperClientUtil configurationClient, String key){
private static void setSystemPropertie(ZookeeperClientUtil configurationClient, String key){
String value = configurationClient.getData(configurationClient.mainPath + "/" + key);
if(StringUtils.isEmpty(value)){
throw new RuntimeException("zookeeper中没有该属性的值:" + key);
}
properties.setProperty(key,value);
System.setProperty(key,value);
}
}
\ No newline at end of file
......@@ -9,15 +9,12 @@ import org.apache.zookeeper.data.ACL;
import org.apache.zookeeper.data.Stat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
//@Component
public class ZookeeperClientUtil {
private static Logger logger = LoggerFactory.getLogger(ZookeeperClientUtil.class);
......@@ -137,13 +134,5 @@ public class ZookeeperClientUtil {
public void setSessionTimeout(int sessionTimeout) {
this.sessionTimeout = sessionTimeout;
}
// public String getMainPath() {
// return mainPath;
// }
// public void setMainPath(String mainPath) {
// this.mainPath = mainPath;
// }
// public static void setServers(String servers) {
// this.servers = servers;
// }
}
......@@ -45,5 +45,3 @@ xxl.job.accessToken=
### xxl-job, i18n (default empty as chinese, "en" as english)
xxl.job.i18n=
###
abc.zookeeper.mainpath=/weixt/conf
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment