Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
iBiz4j Spring R7
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
iBiz-R7后台标准模板
iBiz4j Spring R7
提交
6ea4cfc6
提交
6ea4cfc6
编写于
10月 26, 2021
作者:
yanshaowei
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'dev' of
http://demo.ibizlab.cn/ibizr7sfstdtempl/ibiz4jr7
into dev
上级
edcfd1c1
ab91e362
变更
2
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
117 行增加
和
19 行删除
+117
-19
NacosRegisterConfig.java.ftl
...KGPATH%/%APP_PKGPATH%/config/NacosRegisterConfig.java.ftl
+90
-0
NacosRegisterConfig.java.ftl
...YS_PKGPATH%/core/util/config/NacosRegisterConfig.java.ftl
+27
-19
未找到文件。
SLN/%PUBPRJ%-app/%PUBPRJ%-app-%APP_PKGPATH%/src/main/java/%SYS_PKGPATH%/%APP_PKGPATH%/config/NacosRegisterConfig.java.ftl
0 → 100644
浏览文件 @
6ea4cfc6
<#
ibiztemplate
>
TARGET
=
PSSYSAPP
</#
ibiztemplate
>
<#
assign
packageType
=
""
>
<#
comment
>
前端应用微服务平台配置
</#
comment
>
<#
if
sys
.
getAllPSDevSlnMSDepApps
()??>
<#
list
sys
.
getAllPSDevSlnMSDepApps
()
as
depApp
>
<#
if
depApp
.
getUserParam
(
"ibiz.deploy.packagetype"
,
""
)??
&&
depApp
.
getUserParam
(
"ibiz.deploy.packagetype"
,
""
)
!=''>
<#
assign
packageType
=
depApp
.
getUserParam
(
"ibiz.deploy.packagetype"
,
""
)>
<#
break
>
</#
if
>
<#
break
>
</#
list
>
</#
if
>
<#
if
packageType
==
'war'
>
package
${
pub
.
getPKGCodeName
()}.${
app
.
getPKGCodeName
()?
lower_case
}.
config
;
import
com
.
alibaba
.
cloud
.
nacos
.
registry
.
NacosAutoServiceRegistration
;
import
${
pub
.
getPKGCodeName
()}.
util
.
errors
.
BadRequestAlertException
;
import
lombok
.
extern
.
slf4j
.
Slf4j
;
import
org
.
springframework
.
beans
.
factory
.
annotation
.
Autowired
;
import
org
.
springframework
.
beans
.
factory
.
annotation
.
Value
;
import
org
.
springframework
.
boot
.
ApplicationArguments
;
import
org
.
springframework
.
boot
.
ApplicationRunner
;
import
org
.
springframework
.
stereotype
.
Component
;
import
org
.
springframework
.
util
.
ObjectUtils
;
import
org
.
springframework
.
util
.
StringUtils
;
import
javax
.
management
.
MBeanServer
;
import
javax
.
management
.
ObjectName
;
import
javax
.
management
.
Query
;
import
java
.
lang
.
management
.
ManagementFactory
;
import
java
.
util
.
Set
;
/**
*
外部容器启动服务时,自动注册服务到
nacos
*/
@
Component
@
Slf4j
public
class
NacosRegisterConfig
implements
ApplicationRunner
{
@
Autowired
(
required
=
false
)
private
NacosAutoServiceRegistration
registration
;
@
Value
(
"${r'${server.port:8080}'}"
)
Integer
port
;
@
Override
public
void
run
(
ApplicationArguments
args
)
{
log
.
info
(
"正在尝试将应用程序注册到nacos"
);
if
(
registration
!= null && port != null) {
try
{
String
containerPort
=
getContainerPort
();
if
(
!StringUtils.isEmpty(containerPort)){
registration
.
setPort
(
new
Integer
(
containerPort
));
}
else
{
registration
.
setPort
(
port
);
log
.
info
(
"无法获取外部容器端口,将使用程序默认端口{}"
,
port
);
}
registration
.
start
();
}
catch
(
Exception
e
)
{
throw
new
BadRequestAlertException
(
"应用程序注册到nacos失败,"
+
e
,
""
,
""
);
}
log
.
info
(
"已将应用程序成功注册到nacos"
);
}
else
{
log
.
info
(
"无法获取应用程序端口,将应用程序注册到nacos请求被忽略。"
);
}
}
/**
*
获取外部容器端口
*/
public
String
getContainerPort
(){
String
port
=
null
;
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
;
}
}
</#
if
>
\ No newline at end of file
SLN/%PUBPRJ%-core/src/main/java/%SYS_PKGPATH%/core/util/config/NacosRegisterConfig.java.ftl
浏览文件 @
6ea4cfc6
...
...
@@ -5,32 +5,27 @@ TARGET=PSSYSTEM
<#
comment
>
前端应用微服务平台配置
</#
comment
>
<#
if
sys
.
getAllPSDevSlnMSDepApps
()??>
<#
list
sys
.
getAllPSDevSlnMSDepApps
()
as
depApp
>
<#
if
depApp
.
getPSDCMSPlatform
()??>
<#
assign
appPlatform
=
depApp
.
getPSDCMSPlatform
()>
<#
if
appPlatform
.
getUserParam
(
"ibiz.deploy.packagetype"
,
""
)??>
<#
assign
packageType
=
appPlatform
.
getUserParam
(
"ibiz.deploy.packagetype"
,
""
)>
<#
if
depApp
.
getUserParam
(
"ibiz.deploy.packagetype"
,
""
)??
&&
depApp
.
getUserParam
(
"ibiz.deploy.packagetype"
,
""
)
!=''>
<#
assign
packageType
=
depApp
.
getUserParam
(
"ibiz.deploy.packagetype"
,
""
)>
<#
break
>
</#
if
>
<#
break
>
</#
if
>
</#
list
>
</#
if
>
<#
comment
>
服务接口微服务平台配置
</#
comment
>
<#
if
sys
.
getAllPSDevSlnMSDepAPIs
()??>
<#
list
sys
.
getAllPSDevSlnMSDepAPIs
()
as
depSysApi
>
<#
if
depSysApi
.
getPSDCMSPlatform
()??
>
<#
assign
sysApiPlatform
=
depSysApi
.
getPSDCMSPlatform
()>
<#
if
sysApiPlatform
.
getUserParam
(
"ibiz.deploy.packagetype"
,
""
)??>
<#
assign
packageType
=
sysApiPlatform
.
getUserParam
(
"ibiz.deploy.packagetype"
,
""
)>
<#
if
depSysApi
.
getUserParam
(
"ibiz.deploy.packagetype"
,
""
)??
&&
depSysApi
.
getUserParam
(
"ibiz.deploy.packagetype"
,
""
)
!=''>
<#
assign
packageType
=
depSysApi
.
getUserParam
(
"ibiz.deploy.packagetype"
,
""
)>
<#
break
>
</#
if
>
<#
break
>
</#
if
>
</#
list
>
</#
if
>
<#
if
packageType
==
'war'
>
package
${
pub
.
getPKGCodeName
()}.
core
.
util
.
config
;
import
com
.
alibaba
.
cloud
.
nacos
.
registry
.
NacosAutoServiceRegistration
;
import
com
.
sa
.
ajgl
.
util
.
errors
.
BadRequestAlertException
;
import
${
pub
.
getPKGCodeName
()}
.
util
.
errors
.
BadRequestAlertException
;
import
lombok
.
extern
.
slf4j
.
Slf4j
;
import
org
.
springframework
.
beans
.
factory
.
annotation
.
Autowired
;
import
org
.
springframework
.
beans
.
factory
.
annotation
.
Value
;
...
...
@@ -61,29 +56,42 @@ public class NacosRegisterConfig implements ApplicationRunner {
@
Override
public
void
run
(
ApplicationArguments
args
)
{
log
.
info
(
"正在尝试将应用程序注册到nacos"
);
if
(
registration
!= null && port != null) {
try
{
String
containerPort
=
getContainerPort
();
if
(
!StringUtils.isEmpty(containerPort)){
log
.
info
(
"正在尝试将应用程序注册到nacos,端口号为:{}"
,
containerPort
);
registration
.
setPort
(
new
Integer
(
containerPort
));
registration
.
start
();
}
else
{
registration
.
setPort
(
port
);
log
.
info
(
"无法获取外部容器端口,将使用程序默认端口{}"
,
port
);
}
registration
.
start
();
}
catch
(
Exception
e
)
{
throw
new
BadRequestAlertException
(
"应用程序注册到nacos失败,"
+
e
,
""
,
""
);
}
log
.
info
(
"已将应用程序成功注册到nacos"
);
}
else
{
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
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录