Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
熊鹏飞
/
xxljob220
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
09908bbe
authored
Jul 12, 2017
by
xuxueli
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
properties 加载方式优化
parent
cde0561b
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
29 deletions
xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/PropertiesUtil.java
xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/PropertiesUtil.java
View file @
09908bbe
...
@@ -2,11 +2,12 @@ package com.xxl.job.admin.core.util;
...
@@ -2,11 +2,12 @@ package com.xxl.job.admin.core.util;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.core.io.ClassPathResource
;
import
org.springframework.core.io.Resource
;
import
org.springframework.core.io.support.EncodedResource
;
import
org.springframework.core.io.support.PropertiesLoaderUtils
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.net.URL
;
import
java.util.Properties
;
import
java.util.Properties
;
/**
/**
...
@@ -17,36 +18,16 @@ public class PropertiesUtil {
...
@@ -17,36 +18,16 @@ public class PropertiesUtil {
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
PropertiesUtil
.
class
);
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
PropertiesUtil
.
class
);
private
static
final
String
file_name
=
"xxl-job-admin.properties"
;
private
static
final
String
file_name
=
"xxl-job-admin.properties"
;
/**
* load properties
public
static
String
getString
(
String
key
)
{
* @param propertyFileName
Properties
prop
=
null
;
* @return
*/
public
static
Properties
loadProperties
(
String
propertyFileName
)
{
Properties
prop
=
new
Properties
();
InputStreamReader
in
=
null
;
try
{
URL
url
=
null
;
ClassLoader
loder
=
Thread
.
currentThread
().
getContextClassLoader
();
url
=
loder
.
getResource
(
propertyFileName
);
in
=
new
InputStreamReader
(
new
FileInputStream
(
url
.
getPath
()),
"UTF-8"
);
prop
.
load
(
in
);
}
catch
(
IOException
e
)
{
logger
.
error
(
e
.
getMessage
(),
e
);
}
finally
{
if
(
in
!=
null
)
{
try
{
try
{
in
.
close
();
Resource
resource
=
new
ClassPathResource
(
file_name
);
EncodedResource
encodedResource
=
new
EncodedResource
(
resource
,
"UTF-8"
);
prop
=
PropertiesLoaderUtils
.
loadProperties
(
encodedResource
);
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
logger
.
error
(
e
.
getMessage
(),
e
);
logger
.
error
(
e
.
getMessage
(),
e
);
}
}
}
}
return
prop
;
}
public
static
String
getString
(
String
key
)
{
Properties
prop
=
loadProperties
(
file_name
);
if
(
prop
!=
null
)
{
if
(
prop
!=
null
)
{
return
prop
.
getProperty
(
key
);
return
prop
.
getProperty
(
key
);
}
}
...
...
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