Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
apollo
Project
Overview
Details
Activity
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
openSource
apollo
Commits
74a39156
Commit
74a39156
authored
Apr 30, 2017
by
张乐
Committed by
GitHub
Apr 30, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #607 from nobodyiam/refine-apollo-env-search
load config file from working directory first
parents
0e8163e5
26cc1705
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
1 deletion
+18
-1
ResourceUtils.java
.../com/ctrip/framework/apollo/core/utils/ResourceUtils.java
+18
-1
No files found.
apollo-core/src/main/java/com/ctrip/framework/apollo/core/utils/ResourceUtils.java
View file @
74a39156
...
...
@@ -9,16 +9,18 @@ import java.io.IOException;
import
java.io.InputStream
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.util.Enumeration
;
import
java.util.Properties
;
public
class
ResourceUtils
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
ResourceUtils
.
class
);
private
static
final
String
[]
DEFAULT_FILE_SEARCH_LOCATIONS
=
new
String
[]{
"./config/"
,
"./"
};
@SuppressWarnings
(
"unchecked"
)
public
static
Properties
readConfigFile
(
String
configPath
,
Properties
defaults
)
{
InputStream
in
=
ClassLoaderUtil
.
getLoader
().
getResourceAsStream
(
configPath
);
InputStream
in
=
loadConfigFileFromDefaultSearchLocations
(
configPath
);
logger
.
debug
(
"Reading config from resource {}"
,
configPath
);
Properties
props
=
new
Properties
();
try
{
...
...
@@ -65,4 +67,19 @@ public class ResourceUtils {
}
return
props
;
}
private
static
InputStream
loadConfigFileFromDefaultSearchLocations
(
String
configPath
)
{
for
(
String
searchLocation
:
DEFAULT_FILE_SEARCH_LOCATIONS
)
{
try
{
File
candidate
=
Paths
.
get
(
searchLocation
,
configPath
).
toFile
();
if
(
candidate
.
exists
()
&&
candidate
.
isFile
()
&&
candidate
.
canRead
())
{
return
new
FileInputStream
(
candidate
);
}
}
catch
(
Throwable
ex
)
{
//ignore
}
}
return
ClassLoaderUtil
.
getLoader
().
getResourceAsStream
(
configPath
);
}
}
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