Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
discovery
Overview
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
陈文顺
discovery
Commits
f2c18352
Commit
f2c18352
authored
Sep 09, 2018
by
Nepxion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Nacos配置支持客户自定义
parent
5b397658
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
7 deletions
+23
-7
discovery-common-nacos/pom.xml
+3
-2
discovery-common-nacos/src/main/java/com/nepxion/discovery/common/nacos/configuration/NacosAutoConfiguration.java
+15
-3
discovery-common-nacos/src/main/java/com/nepxion/discovery/common/nacos/constant/NacosConstant.java
+5
-2
No files found.
discovery-common-nacos/pom.xml
View file @
f2c18352
...
...
@@ -21,8 +21,8 @@
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-
context
</artifactId>
<groupId>
org.springframework
.boot
</groupId>
<artifactId>
spring-
boot-autoconfigure
</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
discovery-common-nacos/src/main/java/com/nepxion/discovery/common/nacos/configuration/NacosAutoConfiguration.java
View file @
f2c18352
...
...
@@ -11,7 +11,9 @@ package com.nepxion.discovery.common.nacos.configuration;
import
java.util.Properties
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.core.env.Environment
;
...
...
@@ -28,11 +30,21 @@ public class NacosAutoConfiguration {
private
Environment
environment
;
@Bean
@ConditionalOnMissingBean
public
ConfigService
configService
()
throws
NacosException
{
String
url
=
environment
.
getProperty
(
NacosConstant
.
URL
);
Properties
properties
=
new
Properties
();
properties
.
put
(
NacosConstant
.
URL_KEY
,
url
);
String
url
=
environment
.
getProperty
(
NacosConstant
.
URL
);
if
(
StringUtils
.
isNotEmpty
(
url
))
{
properties
.
put
(
NacosConstant
.
SERVER_ADDR
,
url
);
}
else
{
throw
new
IllegalArgumentException
(
"Url can't be null or empty"
);
}
String
namespace
=
environment
.
getProperty
(
NacosConstant
.
NAMESPACE
);
if
(
StringUtils
.
isNotEmpty
(
namespace
))
{
properties
.
put
(
NacosConstant
.
NAMESPACE
,
namespace
);
}
return
NacosFactory
.
createConfigService
(
properties
);
}
...
...
discovery-common-nacos/src/main/java/com/nepxion/discovery/common/nacos/constant/NacosConstant.java
View file @
f2c18352
...
...
@@ -9,10 +9,12 @@ package com.nepxion.discovery.common.nacos.constant;
* @version 1.0
*/
public
class
NacosConstant
{
public
static
final
String
URL_KEY
=
"serverAddr"
;
import
com.alibaba.nacos.api.PropertyKeyConst
;
public
class
NacosConstant
extends
PropertyKeyConst
{
public
static
final
String
URL
=
"nacos.url"
;
public
static
final
String
TIMEOUT
=
"nacos.timout"
;
public
static
final
String
NAMESPACE
=
"nacos.namespace"
;
public
static
final
long
DEFAULT_TIMEOUT
=
30000
;
}
\ 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