Commit d1e9ab1b authored by 刘晓滨's avatar 刘晓滨

Merge branch 'chs_master_1104' into 'master'

perf(springboot):动态分配端口 See merge request !16
parents d2fb7466 6b5879b8
......@@ -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
......@@ -22,6 +22,9 @@ public class XxlJobExecutorApplication {
* @param args
*/
private static void initZookeeperAddres(String[] args){
if(args == null || args.length == 0){
throw new RuntimeException("请传入zookeeper的地址");
}
String addres = "zookeeper://" + args[0];
Properties properties = new Properties();
properties.setProperty("dubbo.registry.address",addres);
......
# web port
server.port=8081
# web port 等于0时自动获取
server.port=0
# log config
logging.config=classpath:logback.xml
......@@ -11,7 +11,8 @@ xxl.job.admin.addresses=http://127.0.0.1:8181/xxl-job-admin
### xxl-job executor address
xxl.job.executor.appname=com-spacetech-service-xxl-job-springboot
xxl.job.executor.ip=
xxl.job.executor.port=9999
### 执行器端口号 [选填]:小于等于0则自动获取;默认端口为9999,单机部署多个执行器时,注意要配置不同执行器端口;
xxl.job.executor.port=0
### xxl-job, access token
xxl.job.accessToken=
......
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