|
@@ -27,13 +27,12 @@ public class ZdStartApplication {
|
|
|
* 运行服务
|
|
* 运行服务
|
|
|
*
|
|
*
|
|
|
* @param appName -- 应用名
|
|
* @param appName -- 应用名
|
|
|
- * @param isShareDataSource 是否共用数据库,ture-是,fasle-否
|
|
|
|
|
* @param source
|
|
* @param source
|
|
|
* @param args
|
|
* @param args
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
- public static ConfigurableApplicationContext run(String appName, Boolean isShareDataSource, Class<?> source, String... args) {
|
|
|
|
|
- SpringApplicationBuilder builder = createSpringApplicationBuilder(appName, isShareDataSource, source, args);
|
|
|
|
|
|
|
+ public static ConfigurableApplicationContext run(String appName, Class<?> source, String... args) {
|
|
|
|
|
+ SpringApplicationBuilder builder = createSpringApplicationBuilder(appName, source, args);
|
|
|
return builder.run(args);
|
|
return builder.run(args);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -41,12 +40,11 @@ public class ZdStartApplication {
|
|
|
* 创建ApplicationBuilder
|
|
* 创建ApplicationBuilder
|
|
|
*
|
|
*
|
|
|
* @param appName -- 应用名
|
|
* @param appName -- 应用名
|
|
|
- * @param isShareDataSource 是否共用数据库,ture-是,fasle-否
|
|
|
|
|
* @param source
|
|
* @param source
|
|
|
* @param args
|
|
* @param args
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
- public static SpringApplicationBuilder createSpringApplicationBuilder(String appName, Boolean isShareDataSource, Class<?> source, String... args) {
|
|
|
|
|
|
|
+ public static SpringApplicationBuilder createSpringApplicationBuilder(String appName, Class<?> source, String... args) {
|
|
|
Assert.hasText(appName, "[appName]服务名不能为空");
|
|
Assert.hasText(appName, "[appName]服务名不能为空");
|
|
|
ConfigurableEnvironment environment = new StandardEnvironment();
|
|
ConfigurableEnvironment environment = new StandardEnvironment();
|
|
|
MutablePropertySources propertySources = environment.getPropertySources();
|
|
MutablePropertySources propertySources = environment.getPropertySources();
|
|
@@ -67,10 +65,8 @@ public class ZdStartApplication {
|
|
|
if (activeProfileList.size() != 1) {
|
|
if (activeProfileList.size() != 1) {
|
|
|
throw new RuntimeException("同时存在环境变量:[" + StringUtils.arrayToCommaDelimitedString(activeProfiles) + "]");
|
|
throw new RuntimeException("同时存在环境变量:[" + StringUtils.arrayToCommaDelimitedString(activeProfiles) + "]");
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
profile = activeProfileList.get(0);
|
|
profile = activeProfileList.get(0);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
String startJarPath = Objects.requireNonNull(ZdStartApplication.class.getResource("/")).getPath().split("!")[0];
|
|
String startJarPath = Objects.requireNonNull(ZdStartApplication.class.getResource("/")).getPath().split("!")[0];
|
|
|
String activePros = joinFun.apply(activeProfileList.toArray());
|
|
String activePros = joinFun.apply(activeProfileList.toArray());
|
|
|
System.out.printf("============ 启动中,读取到的环境变量:[%s],jar地址:[%s]============ %n", activePros, startJarPath);
|
|
System.out.printf("============ 启动中,读取到的环境变量:[%s],jar地址:[%s]============ %n", activePros, startJarPath);
|
|
@@ -93,14 +89,10 @@ public class ZdStartApplication {
|
|
|
props.setProperty("spring.cloud.nacos.discovery.namespace", nameSpace);
|
|
props.setProperty("spring.cloud.nacos.discovery.namespace", nameSpace);
|
|
|
props.setProperty("spring.cloud.nacos.config.namespace", nameSpace);
|
|
props.setProperty("spring.cloud.nacos.config.namespace", nameSpace);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- String prefixName = (isShareDataSource == null || isShareDataSource)?LauncherConstant.NACOS_CONFIG_NAME:appName;
|
|
|
|
|
- props.setProperty("spring.cloud.nacos.config.prefix", prefixName);
|
|
|
|
|
|
|
+ props.setProperty("spring.cloud.nacos.config.prefix", appName);
|
|
|
props.setProperty("spring.cloud.nacos.config.file-extension", "yml");
|
|
props.setProperty("spring.cloud.nacos.config.file-extension", "yml");
|
|
|
props.setProperty("spring.cloud.nacos.config.shared-configs", "application.yml");
|
|
props.setProperty("spring.cloud.nacos.config.shared-configs", "application.yml");
|
|
|
- //props.setProperty("spring.cloud.nacos.config.extension-configs[0].data-id", "application.yml");
|
|
|
|
|
-
|
|
|
|
|
- log.info("============ nacos配置信息 addr:[{}], namespace:[{}],prefixName:[{}] ===========", new Object[]{addr, nameSpace, prefixName});
|
|
|
|
|
|
|
+ log.info("============ nacos配置信息 addr:[{}], namespace:[{}] ===========", new Object[]{addr, nameSpace});
|
|
|
return builder;
|
|
return builder;
|
|
|
}
|
|
}
|
|
|
|
|
|