提交 ab91e362 编写于 作者: zhouweidong's avatar zhouweidong

项目支持打war包

上级 bf7844c4
......@@ -51,11 +51,13 @@ public class NacosRegisterConfig implements ApplicationRunner {
if (registration != null && port != null) {
try {
String containerPort = getContainerPort();
if(StringUtils.isEmpty(containerPort)){
log.info("无法获取应用程序端口,将应用程序注册到nacos请求被忽略");
return;
if(!StringUtils.isEmpty(containerPort)){
registration.setPort(new Integer(containerPort));
}
else{
registration.setPort(port);
log.info("无法获取外部容器端口,将使用程序默认端口{}",port);
}
registration.setPort(new Integer(containerPort));
registration.start();
} catch (Exception e) {
throw new BadRequestAlertException("应用程序注册到nacos失败,"+e,"","");
......@@ -63,21 +65,26 @@ public class NacosRegisterConfig implements ApplicationRunner {
log.info("已将应用程序成功注册到nacos");
}
else{
log.info("无法获取应用程序端口,将应用程序注册到nacos请求被忽略");
log.info("无法获取应用程序端口,将应用程序注册到nacos请求被忽略");
}
}
/**
* 获取外部容器端口
*/
public String getContainerPort() throws Exception {
public String getContainerPort(){
String port = null;
MBeanServer beanServer = ManagementFactory.getPlatformMBeanServer();
Set<ObjectName> objectNames = beanServer.queryNames(new ObjectName("*:type=Connector,*"), Query.match(Query.attr("protocol"), Query.value("HTTP/1.1")));
if(!ObjectUtils.isEmpty(objectNames)){
port = objectNames.iterator().next().getKeyProperty("port");
try {
MBeanServer beanServer = ManagementFactory.getPlatformMBeanServer();
Set<ObjectName> objectNames = beanServer.queryNames(new ObjectName("*:type=Connector,*"), Query.match(Query.attr("protocol"), Query.value("HTTP/1.1")));
if(!ObjectUtils.isEmpty(objectNames)){
port = objectNames.iterator().next().getKeyProperty("port");
}
}
catch (Exception e) {
log.error("获取外部容器端口失败!"+e);
}
return port;
return port;
}
}
</#if>
\ No newline at end of file
......@@ -60,11 +60,13 @@ public class NacosRegisterConfig implements ApplicationRunner {
if (registration != null && port != null) {
try {
String containerPort = getContainerPort();
if(StringUtils.isEmpty(containerPort)){
log.info("无法获取应用程序端口,将应用程序注册到nacos请求被忽略");
return;
if(!StringUtils.isEmpty(containerPort)){
registration.setPort(new Integer(containerPort));
}
else{
registration.setPort(port);
log.info("无法获取外部容器端口,将使用程序默认端口{}",port);
}
registration.setPort(new Integer(containerPort));
registration.start();
} catch (Exception e) {
throw new BadRequestAlertException("应用程序注册到nacos失败,"+e,"","");
......@@ -72,19 +74,24 @@ public class NacosRegisterConfig implements ApplicationRunner {
log.info("已将应用程序成功注册到nacos");
}
else{
log.info("无法获取应用程序端口,将应用程序注册到nacos请求被忽略");
log.info("无法获取应用程序端口,将应用程序注册到nacos请求被忽略");
}
}
/**
* 获取外部容器端口
*/
public String getContainerPort() throws Exception {
public String getContainerPort(){
String port = null;
MBeanServer beanServer = ManagementFactory.getPlatformMBeanServer();
Set<ObjectName> objectNames = beanServer.queryNames(new ObjectName("*:type=Connector,*"), Query.match(Query.attr("protocol"), Query.value("HTTP/1.1")));
if(!ObjectUtils.isEmpty(objectNames)){
port = objectNames.iterator().next().getKeyProperty("port");
try {
MBeanServer beanServer = ManagementFactory.getPlatformMBeanServer();
Set<ObjectName> objectNames = beanServer.queryNames(new ObjectName("*:type=Connector,*"), Query.match(Query.attr("protocol"), Query.value("HTTP/1.1")));
if(!ObjectUtils.isEmpty(objectNames)){
port = objectNames.iterator().next().getKeyProperty("port");
}
}
catch (Exception e) {
log.error("获取外部容器端口失败!"+e);
}
return port;
}
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册