Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
W
wj-datacenter-platform
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
jinan
wj-datacenter-platform
Commits
d9a857a4
Commit
d9a857a4
authored
May 22, 2024
by
hanbing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Flink 任务环境变量占位符解析
parent
02a1ac3b
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
28 additions
and
2 deletions
+28
-2
PropertiesHelper.java
...main/java/com/wanji/indicators/util/PropertiesHelper.java
+26
-0
config.properties
wj-realtime-computing/src/main/resources/config.properties
+1
-1
config_changsha.properties
...e-computing/src/main/resources/config_changsha.properties
+0
-0
config_jinan.properties
...time-computing/src/main/resources/config_jinan.properties
+0
-0
config_mengzi.properties
...ime-computing/src/main/resources/config_mengzi.properties
+0
-0
spring-mybatis.xml
wj-realtime-computing/src/main/resources/spring-mybatis.xml
+1
-1
No files found.
wj-realtime-computing/src/main/java/com/wanji/indicators/util/PropertiesHelper.java
View file @
d9a857a4
...
@@ -4,8 +4,11 @@ import org.apache.commons.lang3.StringUtils;
...
@@ -4,8 +4,11 @@ import org.apache.commons.lang3.StringUtils;
import
java.io.*
;
import
java.io.*
;
import
java.nio.charset.Charset
;
import
java.nio.charset.Charset
;
import
java.util.Map
;
import
java.util.Properties
;
import
java.util.Properties
;
import
java.util.UUID
;
import
java.util.UUID
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
public
class
PropertiesHelper
implements
Serializable
{
public
class
PropertiesHelper
implements
Serializable
{
private
Properties
properties
;
private
Properties
properties
;
...
@@ -33,6 +36,8 @@ public class PropertiesHelper implements Serializable {
...
@@ -33,6 +36,8 @@ public class PropertiesHelper implements Serializable {
InputStream
inputStream
=
PropertiesHelper
.
class
.
getResourceAsStream
(
"/config.properties"
);
InputStream
inputStream
=
PropertiesHelper
.
class
.
getResourceAsStream
(
"/config.properties"
);
BufferedReader
bf
=
new
BufferedReader
(
new
InputStreamReader
(
inputStream
,
Charset
.
defaultCharset
()));
BufferedReader
bf
=
new
BufferedReader
(
new
InputStreamReader
(
inputStream
,
Charset
.
defaultCharset
()));
properties
.
load
(
bf
);
properties
.
load
(
bf
);
// 环境变量解析
resolvePlaceholders
();
bf
.
close
();
bf
.
close
();
inputStream
.
close
();
inputStream
.
close
();
...
@@ -48,6 +53,27 @@ public class PropertiesHelper implements Serializable {
...
@@ -48,6 +53,27 @@ public class PropertiesHelper implements Serializable {
}
}
return
this
.
properties
;
return
this
.
properties
;
}
}
private
void
resolvePlaceholders
()
{
Pattern
pattern
=
Pattern
.
compile
(
"\\$\\{([^:}]+):([^}]+)\\}"
);
for
(
Map
.
Entry
<
Object
,
Object
>
entry
:
properties
.
entrySet
())
{
String
key
=
(
String
)
entry
.
getKey
();
String
value
=
(
String
)
entry
.
getValue
();
Matcher
matcher
=
pattern
.
matcher
(
value
);
StringBuffer
resolvedValue
=
new
StringBuffer
();
while
(
matcher
.
find
())
{
String
envKey
=
matcher
.
group
(
1
);
String
defaultValue
=
matcher
.
group
(
2
);
String
envValue
=
System
.
getProperty
(
envKey
,
System
.
getenv
(
envKey
));
if
(
envValue
==
null
)
{
envValue
=
defaultValue
;
}
matcher
.
appendReplacement
(
resolvedValue
,
envValue
);
}
matcher
.
appendTail
(
resolvedValue
);
properties
.
setProperty
(
key
,
resolvedValue
.
toString
());
}
}
public
synchronized
Properties
getConsumerProperties
()
{
public
synchronized
Properties
getConsumerProperties
()
{
Properties
consumerProps
=
new
Properties
();
Properties
consumerProps
=
new
Properties
();
...
...
wj-realtime-computing/src/main/resources/config.properties
View file @
d9a857a4
config_name
=
config_dev.properties
config_name
=
config_${my.profile:dev}.properties
\ No newline at end of file
\ No newline at end of file
wj-realtime-computing/src/main/resources/config_c
s
.properties
→
wj-realtime-computing/src/main/resources/config_c
hangsha
.properties
View file @
d9a857a4
File moved
wj-realtime-computing/src/main/resources/config_jn.properties
→
wj-realtime-computing/src/main/resources/config_j
ina
n.properties
View file @
d9a857a4
File moved
wj-realtime-computing/src/main/resources/config_m
z
.properties
→
wj-realtime-computing/src/main/resources/config_m
engzi
.properties
View file @
d9a857a4
File moved
wj-realtime-computing/src/main/resources/spring-mybatis.xml
View file @
d9a857a4
...
@@ -10,7 +10,7 @@
...
@@ -10,7 +10,7 @@
<!-- 加载配置文件 -->
<!-- 加载配置文件 -->
<!--<context:property-placeholder location="classpath:db.properties"/>-->
<!--<context:property-placeholder location="classpath:db.properties"/>-->
<context:property-placeholder
location=
"classpath:db/
dev
/db.properties"
/>
<context:property-placeholder
location=
"classpath:db/
${my.profile:dev}
/db.properties"
/>
<!-- 配置数据源 -->
<!-- 配置数据源 -->
<bean
id=
"dataSource"
class=
"com.alibaba.druid.pool.DruidDataSource"
init-method=
"init"
destroy-method=
"close"
>
<bean
id=
"dataSource"
class=
"com.alibaba.druid.pool.DruidDataSource"
init-method=
"init"
destroy-method=
"close"
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment