Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
YZG
yzg-util
Commits
6f0d0191
Commit
6f0d0191
authored
Apr 30, 2019
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
自动变量处理
parent
915bd245
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
0 deletions
+46
-0
YzgEnvironmentPostProcessor.java
...om/yanzuoguang/cloud/env/YzgEnvironmentPostProcessor.java
+45
-0
spring.factories
yzg-util-cloud/src/main/resources/META-INF/spring.factories
+1
-0
No files found.
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/env/YzgEnvironmentPostProcessor.java
0 → 100644
View file @
6f0d0191
package
com
.
yanzuoguang
.
cloud
.
env
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.InputStream
;
import
java.util.Properties
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.env.EnvironmentPostProcessor
;
import
org.springframework.core.env.ConfigurableEnvironment
;
import
org.springframework.core.env.PropertiesPropertySource
;
import
org.springframework.stereotype.Component
;
/**
* 环境变量处理
*/
@Component
public
class
YzgEnvironmentPostProcessor
implements
EnvironmentPostProcessor
{
@Override
public
void
postProcessEnvironment
(
ConfigurableEnvironment
environment
,
SpringApplication
application
)
{
String
key
=
"yzg.config.url"
;
String
property
=
environment
.
getProperty
(
key
);
if
(
StringHelper
.
isEmpty
(
property
))
{
return
;
}
File
file
=
new
File
(
property
);
if
(!
file
.
exists
())
{
return
;
}
try
(
InputStream
input
=
new
FileInputStream
(
property
))
{
Properties
properties
=
new
Properties
();
properties
.
load
(
input
);
PropertiesPropertySource
propertySource
=
new
PropertiesPropertySource
(
"ve"
,
properties
);
environment
.
getPropertySources
().
addLast
(
propertySource
);
System
.
out
.
println
(
"====加载外部配置文件"
+
property
+
"完毕===="
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
\ No newline at end of file
yzg-util-cloud/src/main/resources/META-INF/spring.factories
0 → 100644
View file @
6f0d0191
org.springframework.boot.env.EnvironmentPostProcessor=com.yanzuoguang.cloud.env.YzgEnvironmentPostProcessor
\ No newline at end of file
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