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
3f86ba0a
Commit
3f86ba0a
authored
Aug 01, 2018
by
Nepxion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化配置方式,做到零配置可运行
parent
442af878
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
33 additions
and
23 deletions
+33
-23
discovery-common/src/main/java/com/nepxion/discovery/common/constant/DiscoveryConstant.java
+2
-0
discovery-plugin-config-center/src/main/java/com/nepxion/discovery/plugin/configcenter/loader/LocalConfigLoader.java
+7
-1
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/context/PluginContextAware.java
+3
-2
discovery-springcloud-example-gateway/src/main/resources/bootstrap.properties
+7
-7
discovery-springcloud-example-service/src/main/resources/bootstrap.properties
+7
-6
discovery-springcloud-example-zuul/src/main/resources/bootstrap.properties
+7
-7
No files found.
discovery-common/src/main/java/com/nepxion/discovery/common/constant/DiscoveryConstant.java
View file @
3f86ba0a
...
@@ -32,6 +32,8 @@ public class DiscoveryConstant {
...
@@ -32,6 +32,8 @@ public class DiscoveryConstant {
public
static
final
String
XML_FORMAT
=
"xml"
;
public
static
final
String
XML_FORMAT
=
"xml"
;
public
static
final
String
JSON_FORMAT
=
"json"
;
public
static
final
String
JSON_FORMAT
=
"json"
;
public
static
final
String
PREFIX_CLASSPATH
=
"classpath:"
;
public
static
final
String
PREFIX_FILE
=
"file:"
;
public
static
final
String
DATE_FORMAT
=
"yyyy-MM-dd HH:mm:ss.SSS"
;
public
static
final
String
DATE_FORMAT
=
"yyyy-MM-dd HH:mm:ss.SSS"
;
public
static
final
String
ENCODING_UTF_8
=
"UTF-8"
;
public
static
final
String
ENCODING_UTF_8
=
"UTF-8"
;
...
...
discovery-plugin-config-center/src/main/java/com/nepxion/discovery/plugin/configcenter/loader/LocalConfigLoader.java
View file @
3f86ba0a
...
@@ -13,12 +13,16 @@ import java.io.InputStream;
...
@@ -13,12 +13,16 @@ import java.io.InputStream;
import
org.apache.commons.io.IOUtils
;
import
org.apache.commons.io.IOUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContext
;
import
com.nepxion.discovery.common.constant.DiscoveryConstant
;
import
com.nepxion.discovery.common.constant.DiscoveryConstant
;
public
abstract
class
LocalConfigLoader
implements
ConfigLoader
{
public
abstract
class
LocalConfigLoader
implements
ConfigLoader
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
LocalConfigLoader
.
class
);
@Autowired
@Autowired
private
ApplicationContext
applicationContext
;
private
ApplicationContext
applicationContext
;
...
@@ -26,9 +30,11 @@ public abstract class LocalConfigLoader implements ConfigLoader {
...
@@ -26,9 +30,11 @@ public abstract class LocalConfigLoader implements ConfigLoader {
public
String
getConfig
()
throws
Exception
{
public
String
getConfig
()
throws
Exception
{
String
path
=
getPath
();
String
path
=
getPath
();
if
(
StringUtils
.
isEmpty
(
path
))
{
if
(
StringUtils
.
isEmpty
(
path
))
{
throw
new
IllegalArgumentException
(
"
L
ocal path isn't set"
);
throw
new
IllegalArgumentException
(
"
Config l
ocal path isn't set"
);
}
}
LOG
.
info
(
"Config local path is {}"
,
path
);
InputStream
inputStream
=
null
;
InputStream
inputStream
=
null
;
try
{
try
{
String
filePath
=
applicationContext
.
getEnvironment
().
resolvePlaceholders
(
path
);
String
filePath
=
applicationContext
.
getEnvironment
().
resolvePlaceholders
(
path
);
...
...
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/context/PluginContextAware.java
View file @
3f86ba0a
...
@@ -9,6 +9,7 @@ package com.nepxion.discovery.plugin.framework.context;
...
@@ -9,6 +9,7 @@ package com.nepxion.discovery.plugin.framework.context;
* @version 1.0
* @version 1.0
*/
*/
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.BeansException
;
import
org.springframework.beans.BeansException
;
import
org.springframework.beans.factory.NoSuchBeanDefinitionException
;
import
org.springframework.beans.factory.NoSuchBeanDefinitionException
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContext
;
...
@@ -121,11 +122,11 @@ public class PluginContextAware implements ApplicationContextAware {
...
@@ -121,11 +122,11 @@ public class PluginContextAware implements ApplicationContextAware {
}
}
public
static
String
getConfigFormat
(
Environment
environment
)
{
public
static
String
getConfigFormat
(
Environment
environment
)
{
return
environment
.
getProperty
(
DiscoveryConstant
.
SPRING_APPLICATION_CONFIG_FORMAT
,
DiscoveryConstant
.
XML_FORMAT
);
return
environment
.
getProperty
(
DiscoveryConstant
.
SPRING_APPLICATION_CONFIG_FORMAT
,
String
.
class
,
DiscoveryConstant
.
XML_FORMAT
);
}
}
public
static
String
getConfigPath
(
Environment
environment
)
{
public
static
String
getConfigPath
(
Environment
environment
)
{
return
environment
.
getProperty
(
DiscoveryConstant
.
SPRING_APPLICATION_CONFIG_PATH
);
return
environment
.
getProperty
(
DiscoveryConstant
.
SPRING_APPLICATION_CONFIG_PATH
,
String
.
class
,
StringUtils
.
equals
(
getConfigFormat
(
environment
),
DiscoveryConstant
.
XML_FORMAT
)
?
DiscoveryConstant
.
PREFIX_CLASSPATH
+
DiscoveryConstant
.
RULE
+
"."
+
DiscoveryConstant
.
XML_FORMAT
:
DiscoveryConstant
.
PREFIX_CLASSPATH
+
DiscoveryConstant
.
RULE
+
"."
+
DiscoveryConstant
.
JSON_FORMAT
);
}
}
public
static
String
getGroupKey
(
Environment
environment
)
{
public
static
String
getGroupKey
(
Environment
environment
)
{
...
...
discovery-springcloud-example-gateway/src/main/resources/bootstrap.properties
View file @
3f86ba0a
...
@@ -38,16 +38,16 @@ management.security.enabled=false
...
@@ -38,16 +38,16 @@ management.security.enabled=false
# Plugin config
# Plugin config
# 开启和关闭服务注册层面的控制。一旦关闭,服务注册的黑/白名单过滤功能将失效,最大注册数的限制过滤功能将失效。缺失则默认为true
# 开启和关闭服务注册层面的控制。一旦关闭,服务注册的黑/白名单过滤功能将失效,最大注册数的限制过滤功能将失效。缺失则默认为true
spring.application.register.control.enabled
=
true
#
spring.application.register.control.enabled=true
# 开启和关闭服务发现层面的控制。一旦关闭,服务多版本调用的控制功能将失效,动态屏蔽指定IP地址的服务实例被发现的功能将失效。缺失则默认为true
# 开启和关闭服务发现层面的控制。一旦关闭,服务多版本调用的控制功能将失效,动态屏蔽指定IP地址的服务实例被发现的功能将失效。缺失则默认为true
spring.application.discovery.control.enabled
=
true
#
spring.application.discovery.control.enabled=true
# 开启和关闭通过Rest方式对规则配置的控制和推送。一旦关闭,只能通过远程配置中心来控制和推送。缺失则默认为true
# 开启和关闭通过Rest方式对规则配置的控制和推送。一旦关闭,只能通过远程配置中心来控制和推送。缺失则默认为true
spring.application.config.rest.control.enabled
=
true
#
spring.application.config.rest.control.enabled=true
# 规则文件的格式,支持xml和json。缺失则默认为xml
# 规则文件的格式,支持xml和json。缺失则默认为xml
spring.application.config.format
=
xml
#
spring.application.config.format=xml
# spring.application.config.format=json
# spring.application.config.format=json
# 本地规则文件的路径,支持两种方式:classpath:rule.xml(rule.json) - 规则文件放在resources目录下,便于打包进jar;file:rule.xml(rule.json) - 规则文件放在工程根目录下,放置在外部便于修改。缺失则默认为不装载本地规则
# 本地规则文件的路径,支持两种方式:classpath:rule.xml(rule.json) - 规则文件放在resources目录下,便于打包进jar;file:rule.xml(rule.json) - 规则文件放在工程根目录下,放置在外部便于修改。缺失则默认为不装载本地规则
spring.application.config.path
=
classpath:rule.xml
#
spring.application.config.path=classpath:rule.xml
# spring.application.config.path=classpath:rule.json
# spring.application.config.path=classpath:rule.json
# 为微服务归类的Key,一般通过group字段来归类,例如eureka.instance.metadataMap.group=xxx-group或者eureka.instance.metadataMap.application=xxx-application。缺失则默认为group
# 为微服务归类的Key,一般通过group字段来归类,例如eureka.instance.metadataMap.group=xxx-group或者eureka.instance.metadataMap.application=xxx-application。缺失则默认为group
# spring.application.group.key=group
# spring.application.group.key=group
...
@@ -55,4 +55,4 @@ spring.application.config.path=classpath:rule.xml
...
@@ -55,4 +55,4 @@ spring.application.config.path=classpath:rule.xml
# Plugin strategy config
# Plugin strategy config
# 开启和关闭用户自定义和编程灰度路由策略的控制,例如用户根据业务参数的不同,负载均衡到不同的服务器。缺失则默认为true
# 开启和关闭用户自定义和编程灰度路由策略的控制,例如用户根据业务参数的不同,负载均衡到不同的服务器。缺失则默认为true
spring.application.strategy.control.enabled
=
true
#
spring.application.strategy.control.enabled
=
true
\ No newline at end of file
\ No newline at end of file
discovery-springcloud-example-service/src/main/resources/bootstrap.properties
View file @
3f86ba0a
...
@@ -38,16 +38,16 @@ management.security.enabled=false
...
@@ -38,16 +38,16 @@ management.security.enabled=false
# Plugin config
# Plugin config
# 开启和关闭服务注册层面的控制。一旦关闭,服务注册的黑/白名单过滤功能将失效,最大注册数的限制过滤功能将失效。缺失则默认为true
# 开启和关闭服务注册层面的控制。一旦关闭,服务注册的黑/白名单过滤功能将失效,最大注册数的限制过滤功能将失效。缺失则默认为true
spring.application.register.control.enabled
=
true
#
spring.application.register.control.enabled=true
# 开启和关闭服务发现层面的控制。一旦关闭,服务多版本调用的控制功能将失效,动态屏蔽指定IP地址的服务实例被发现的功能将失效。缺失则默认为true
# 开启和关闭服务发现层面的控制。一旦关闭,服务多版本调用的控制功能将失效,动态屏蔽指定IP地址的服务实例被发现的功能将失效。缺失则默认为true
spring.application.discovery.control.enabled
=
true
#
spring.application.discovery.control.enabled=true
# 开启和关闭通过Rest方式对规则配置的控制和推送。一旦关闭,只能通过远程配置中心来控制和推送。缺失则默认为true
# 开启和关闭通过Rest方式对规则配置的控制和推送。一旦关闭,只能通过远程配置中心来控制和推送。缺失则默认为true
spring.application.config.rest.control.enabled
=
true
#
spring.application.config.rest.control.enabled=true
# 规则文件的格式,支持xml和json。缺失则默认为xml
# 规则文件的格式,支持xml和json。缺失则默认为xml
spring.application.config.format
=
xml
#
spring.application.config.format=xml
# spring.application.config.format=json
# spring.application.config.format=json
# 本地规则文件的路径,支持两种方式:classpath:rule.xml(rule.json) - 规则文件放在resources目录下,便于打包进jar;file:rule.xml(rule.json) - 规则文件放在工程根目录下,放置在外部便于修改。缺失则默认为不装载本地规则
# 本地规则文件的路径,支持两种方式:classpath:rule.xml(rule.json) - 规则文件放在resources目录下,便于打包进jar;file:rule.xml(rule.json) - 规则文件放在工程根目录下,放置在外部便于修改。缺失则默认为不装载本地规则
spring.application.config.path
=
classpath:rule.xml
#
spring.application.config.path=classpath:rule.xml
# spring.application.config.path=classpath:rule.json
# spring.application.config.path=classpath:rule.json
# 为微服务归类的Key,一般通过group字段来归类,例如eureka.instance.metadataMap.group=xxx-group或者eureka.instance.metadataMap.application=xxx-application。缺失则默认为group
# 为微服务归类的Key,一般通过group字段来归类,例如eureka.instance.metadataMap.group=xxx-group或者eureka.instance.metadataMap.application=xxx-application。缺失则默认为group
# spring.application.group.key=group
# spring.application.group.key=group
...
@@ -55,6 +55,6 @@ spring.application.config.path=classpath:rule.xml
...
@@ -55,6 +55,6 @@ spring.application.config.path=classpath:rule.xml
# Plugin strategy config
# Plugin strategy config
# 开启和关闭用户自定义和编程灰度路由策略的控制,例如用户根据业务参数的不同,负载均衡到不同的服务器。缺失则默认为true
# 开启和关闭用户自定义和编程灰度路由策略的控制,例如用户根据业务参数的不同,负载均衡到不同的服务器。缺失则默认为true
spring.application.strategy.control.enabled
=
true
#
spring.application.strategy.control.enabled=true
# 用户自定义和编程灰度路由策略的时候,需要指定对业务Controller类的扫描路径,以便传递上下文对象。该项配置只对服务有效,对网关无效
# 用户自定义和编程灰度路由策略的时候,需要指定对业务Controller类的扫描路径,以便传递上下文对象。该项配置只对服务有效,对网关无效
spring.application.strategy.scan.packages
=
com.nepxion.discovery.plugin.example.service.feign
spring.application.strategy.scan.packages
=
com.nepxion.discovery.plugin.example.service.feign
\ No newline at end of file
discovery-springcloud-example-zuul/src/main/resources/bootstrap.properties
View file @
3f86ba0a
...
@@ -38,16 +38,16 @@ management.security.enabled=false
...
@@ -38,16 +38,16 @@ management.security.enabled=false
# Plugin config
# Plugin config
# 开启和关闭服务注册层面的控制。一旦关闭,服务注册的黑/白名单过滤功能将失效,最大注册数的限制过滤功能将失效。缺失则默认为true
# 开启和关闭服务注册层面的控制。一旦关闭,服务注册的黑/白名单过滤功能将失效,最大注册数的限制过滤功能将失效。缺失则默认为true
spring.application.register.control.enabled
=
true
#
spring.application.register.control.enabled=true
# 开启和关闭服务发现层面的控制。一旦关闭,服务多版本调用的控制功能将失效,动态屏蔽指定IP地址的服务实例被发现的功能将失效。缺失则默认为true
# 开启和关闭服务发现层面的控制。一旦关闭,服务多版本调用的控制功能将失效,动态屏蔽指定IP地址的服务实例被发现的功能将失效。缺失则默认为true
spring.application.discovery.control.enabled
=
true
#
spring.application.discovery.control.enabled=true
# 开启和关闭通过Rest方式对规则配置的控制和推送。一旦关闭,只能通过远程配置中心来控制和推送。缺失则默认为true
# 开启和关闭通过Rest方式对规则配置的控制和推送。一旦关闭,只能通过远程配置中心来控制和推送。缺失则默认为true
spring.application.config.rest.control.enabled
=
true
#
spring.application.config.rest.control.enabled=true
# 规则文件的格式,支持xml和json。缺失则默认为xml
# 规则文件的格式,支持xml和json。缺失则默认为xml
spring.application.config.format
=
xml
#
spring.application.config.format=xml
# spring.application.config.format=json
# spring.application.config.format=json
# 本地规则文件的路径,支持两种方式:classpath:rule.xml(rule.json) - 规则文件放在resources目录下,便于打包进jar;file:rule.xml(rule.json) - 规则文件放在工程根目录下,放置在外部便于修改。缺失则默认为不装载本地规则
# 本地规则文件的路径,支持两种方式:classpath:rule.xml(rule.json) - 规则文件放在resources目录下,便于打包进jar;file:rule.xml(rule.json) - 规则文件放在工程根目录下,放置在外部便于修改。缺失则默认为不装载本地规则
spring.application.config.path
=
classpath:rule.xml
#
spring.application.config.path=classpath:rule.xml
# spring.application.config.path=classpath:rule.json
# spring.application.config.path=classpath:rule.json
# 为微服务归类的Key,一般通过group字段来归类,例如eureka.instance.metadataMap.group=xxx-group或者eureka.instance.metadataMap.application=xxx-application。缺失则默认为group
# 为微服务归类的Key,一般通过group字段来归类,例如eureka.instance.metadataMap.group=xxx-group或者eureka.instance.metadataMap.application=xxx-application。缺失则默认为group
# spring.application.group.key=group
# spring.application.group.key=group
...
@@ -55,4 +55,4 @@ spring.application.config.path=classpath:rule.xml
...
@@ -55,4 +55,4 @@ spring.application.config.path=classpath:rule.xml
# Plugin strategy config
# Plugin strategy config
# 开启和关闭用户自定义和编程灰度路由策略的控制,例如用户根据业务参数的不同,负载均衡到不同的服务器。缺失则默认为true
# 开启和关闭用户自定义和编程灰度路由策略的控制,例如用户根据业务参数的不同,负载均衡到不同的服务器。缺失则默认为true
spring.application.strategy.control.enabled
=
true
#
spring.application.strategy.control.enabled
=
true
\ No newline at end of file
\ 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