简介
Spring Cloud Config为分布式系统中的外部配置提供服务器和客户端支持。使用Config Server,您可以为所有环境中的应用程序管理其外部属性。它非常适合spring应用,也可以使用在其他语言的应用上。
随着应用程序通过从开发到测试和生产的部署流程,您可以管理这些环境之间的配置,并确定应用程序具有迁移时需要运行的一切。
服务器存储后端的默认实现使用git,因此它轻松支持标签版本的配置环境,以及可以访问用于管理内容的各种工具。
Spring Cloud Config服务端特性
- HTTP,为外部配置提供基于资源的API(键值对,或者等价的YAML内容)
- 属性值的加密和解密(对称加密和非对称加密)
- 通过使用@EnableConfigServer在Spring boot应用中非常简单的嵌入。
Config客户端的特性(特指Spring应用)
- 绑定Config服务端,并使用远程的属性源初始化Spring环境。
- 属性值的加密和解密(对称加密和非对称加密)
说明
由于网上一般都是关于git存储的默认式教程,如Spring Cloud Config 分布式配置中心使用教程
但并不是所有公司都使用git,比如我们的生产环境,每个服务都部署在不同的服务器,且无法访问git,所以本文主要记录文件系统存储辅加Eureka服务发现功能的方式。
Server端
依赖
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.yan</groupId>
<artifactId>spring.cloud.config.server</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.0.RELEASE</version>
<relativePath/>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Finchley.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
<version>RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
启动类
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;
@SpringBootApplication
@EnableConfigServer
//@EnableEurekaClient
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}
配置
bootstrap.yml
server:
port: 8888
spring:
application:
name: spring-cloud-config-server
cloud:
config:
server:
native:
search-locations: [classpath:/]
profiles:
active: native
svcA.yml
server:
port: 8081
profile: default
svcA-pro.yml
server:
port: 8082
profile: pro
测试
启动服务,打开网址http://localhost:8888/svcA/pro
,返回值:
{
"name": "svcA",
"profiles": [
"pro"
],
"label": null,
"version": null,
"state": null,
"propertySources": [
{
"name": "classpath:/svcA-pro.yml",
"source": {
"server.port": 8082,
"profile": "pro"
}
},
{
"name": "classpath:/svcA.yml",
"source": {
"server.port": 8081,
"profile": "default"
}
}
]
}
注
如果有返回值,说明我们的配置生效了,从所示URL中可以看出一些端倪,比如,当输入http://localhost:8888/svcA/default
,那么应返回:
{
"name": "svcA",
"profiles": [
"default"
],
"label": null,
"version": null,
"state": null,
"propertySources": [
{
"name": "classpath:/svcA.yml",
"source": {
"server.port": 8081,
"profile": "default"
}
}
]
}
官方文档列举了几种内置访问规则:
/{application}/{profile}[/{label}] <--- 我所采用的方式
/{application}-{profile}.yml
/{label}/{application}-{profile}.yml
/{application}-{profile}.properties
/{label}/{application}-{profile}.properties
由于我们没有使用git,因此没有label也就是分支的概念,所以我们采用不带label的方式访问。
当采用其他方式访问时,结果类似读取配置文件并展示相应内容,如,http://localhost:8888/svcA-pro.yml
返回:
profile: pro
server.port: 8082
Client端
依赖
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.yan</groupId>
<artifactId>spring.cloud.config-client-a</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.0.RELEASE</version>
<relativePath/>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Finchley.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
<version>RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>RELEASE</version>
</dependency>
</dependencies>
</project>
启动类
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@RestController
//@EnableEurekaClient
public class ClientAApplication {
@Value("${profile}")
private String profile;
@GetMapping("/")
public String home() {
return profile;
}
public static void main(String[] args) {
SpringApplication.run(ClientAApplication.class, args);
}
}
配置
bootstrap.yml
spring:
application:
name: svcA
profiles:
active: pro
测试
启动客户端,打印日志如下:
2019-02-22 23:02:36.952 INFO 6252 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$8bdcd989] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.0.RELEASE)
2019-02-22 23:02:37.232 INFO 6252 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:8888
2019-02-22 23:02:37.601 INFO 6252 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Located environment: name=svcA, profiles=[pro], label=null, version=null, state=null
2019-02-22 23:02:37.602 INFO 6252 --- [ main] b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource {name='configService', propertySources=[MapPropertySource {name='classpath:/svcA-pro.yml'}, MapPropertySource {name='classpath:/svcA.yml'}]}
2019-02-22 23:02:37.604 INFO 6252 --- [ main] com.yan.ClientAApplication : The following profiles are active: pro
2019-02-22 23:02:37.889 INFO 6252 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=02bf1a3c-7880-3f25-a1ec-3fbf92e05730
2019-02-22 23:02:37.903 INFO 6252 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$8bdcd989] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-02-22 23:02:38.078 INFO 6252 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8082 (http)
2019-02-22 23:02:38.089 INFO 6252 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-02-22 23:02:38.089 INFO 6252 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/9.0.12
2019-02-22 23:02:38.095 INFO 6252 --- [ main] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [D:\Program Files\Java\jdk1.8.0_191\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\iCLS\;C:\Program Files\Intel\Intel(R) Management Engine Components\iCLS\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;D:\Program Files\Java\jdk1.8.0_191\bin;D:\Program Files\Git\cmd;D:\Program Files\apache-maven-3.6.0\bin;D:\Program Files\gradle-5.0\bin;D:\buildtool\sbt\bin;C:\Users\Yan\AppData\Local\Microsoft\WindowsApps;;.]
2019-02-22 23:02:38.196 INFO 6252 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-02-22 23:02:38.196 INFO 6252 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 582 ms
2019-02-22 23:02:38.210 INFO 6252 --- [ main] o.s.b.w.servlet.ServletRegistrationBean : Servlet dispatcherServlet mapped to [/]
2019-02-22 23:02:38.214 INFO 6252 --- [ main] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2019-02-22 23:02:38.214 INFO 6252 --- [ main] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2019-02-22 23:02:38.214 INFO 6252 --- [ main] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'formContentFilter' to: [/*]
2019-02-22 23:02:38.214 INFO 6252 --- [ main] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2019-02-22 23:02:38.328 INFO 6252 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-02-22 23:02:38.736 INFO 6252 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8082 (http) with context path ''
2019-02-22 23:02:38.738 INFO 6252 --- [ main] com.yan.ClientAApplication : Started ClientAApplication in 2.557 seconds (JVM running for 3.245)
可以看到,我们的端口,已经正确读取,那么,profile是否能正确返回呢?打开http://localhost:8082/
发现正确返回了期待值pro
。
集成Eureka
新建Maven服务spring-cloud-eureka-server
。
依赖
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.yan</groupId>
<artifactId>spring.cloud.eureka.server</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.0.RELEASE</version>
<relativePath/>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Finchley.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
<version>RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
启动类
EurekaServerApplication.java
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {
public static void main(String[] args) {
new SpringApplicationBuilder(EurekaServerApplication.class)
.web(WebApplicationType.SERVLET).run(args);
}
}
配置
application.yaml
spring:
application:
name: eureka-server
server:
port: 8761
eureka:
instance:
hostname: localhost
client:
register-with-eureka: false
fetch-registry: false
测试
打开localhost:8761
,正确返回Eureka页面即可。
集成Config
无论是config-server还是config-client-x,集成方式都差不多,唯一的区别是,config-server服务,不需要额外添加配置,此处只以client-a服务举例。
依赖
添加如下依赖:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
<version>RELEASE</version>
</dependency>
开启服务发现功能注解
在启动类上添加注解@EnableEurekaClient
集成配置
注意,如果是config-server,则只需要添加eureka.client.serviceUrl.defaultZone的配置
bootstrap.yml
spring:
cloud:
config:
discovery:
enabled: true
service-id: spring-cloud-config-server
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
注
此处发现一个问题,就是当服务多了之后,是否使用类似于包的文件夹将其分类存放起来,这样比较人性化,比如,我现在的配置文件夹结构如下:
|- resources
|- bootstrap.yml
|- svcA.yml
|- svcA-pro.yml
当服务多了之后,我可以根据情况变为这样:
|- resources
|- bootstrap.yml
|- svcA
|- svcA.yml
|- svcA-pro.yml
|- svcB
|- svcB.yml
|- svcB-pro.yml
|- svc...
此时,配置就需要发生变更了:
spring:
server:
native:
search-locations: [classpath:/svcA, classpath:/svcB, classpath:/svc...]
为了方便区分,我将svcA-pro.yml中的server.port=8087*
测试
- 启动eureka
- 启动config-server
- 启动config-client-a
查看config-client-a启动日志:
2019-02-23 00:31:12.489 INFO 3244 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://YanWei:8881/
2019-02-23 00:31:12.807 INFO 3244 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Located environment: name=svcA, profiles=[pro], label=null, version=null, state=null
2019-02-23 00:31:12.808 INFO 3244 --- [ main] b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource {name='configService', propertySources=[MapPropertySource {name='classpath:/svcConf/svcA-pro.yml'}]}
2019-02-23 00:31:12.810 INFO 3244 --- [ main] com.yan.ClientAApplication : The following profiles are active: pro
2019-02-23 00:31:13.169 INFO 3244 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=f4124a52-0b01-3d76-8de4-d5ad3011d33a
2019-02-23 00:31:13.207 INFO 3244 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$6d30854e] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-02-23 00:31:13.392 INFO 3244 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8087 (http)
2019-02-23 00:31:13.405 INFO 3244 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-02-23 00:31:13.405 INFO 3244 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/9.0.12
2019-02-23 00:31:13.410 INFO 3244 --- [ main] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [D:\Program Files\Java\jdk1.8.0_191\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\iCLS\;C:\Program Files\Intel\Intel(R) Management Engine Components\iCLS\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;D:\Program Files\Java\jdk1.8.0_191\bin;D:\Program Files\Git\cmd;D:\Program Files\apache-maven-3.6.0\bin;D:\Program Files\gradle-5.0\bin;D:\buildtool\sbt\bin;C:\Users\Yan\AppData\Local\Microsoft\WindowsApps;;.]
2019-02-23 00:31:13.544 INFO 3244 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-02-23 00:31:13.544 INFO 3244 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 726 ms
2019-02-23 00:31:13.560 INFO 3244 --- [ main] o.s.b.w.servlet.ServletRegistrationBean : Servlet dispatcherServlet mapped to [/]
2019-02-23 00:31:13.564 INFO 3244 --- [ main] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2019-02-23 00:31:13.564 INFO 3244 --- [ main] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2019-02-23 00:31:13.564 INFO 3244 --- [ main] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'formContentFilter' to: [/*]
2019-02-23 00:31:13.564 INFO 3244 --- [ main] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2019-02-23 00:31:13.588 WARN 3244 --- [ main] c.n.c.sources.URLConfigurationSource : No URLs will be polled as dynamic configuration sources.
2019-02-23 00:31:13.588 INFO 3244 --- [ main] c.n.c.sources.URLConfigurationSource : To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
2019-02-23 00:31:13.592 WARN 3244 --- [ main] c.n.c.sources.URLConfigurationSource : No URLs will be polled as dynamic configuration sources.
2019-02-23 00:31:13.592 INFO 3244 --- [ main] c.n.c.sources.URLConfigurationSource : To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
2019-02-23 00:31:13.736 INFO 3244 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-02-23 00:31:14.296 INFO 3244 --- [ main] com.netflix.discovery.DiscoveryClient : Shutting down DiscoveryClient ...
2019-02-23 00:31:14.300 INFO 3244 --- [ main] com.netflix.discovery.DiscoveryClient : Completed shut down of DiscoveryClient
2019-02-23 00:31:14.301 WARN 3244 --- [ main] arterDeprecationWarningAutoConfiguration : spring-cloud-starter-eureka is deprecated as of Spring Cloud Netflix 1.4.0, please migrate to spring-cloud-starter-netflix-eureka
2019-02-23 00:31:14.354 INFO 3244 --- [ main] o.s.c.n.eureka.InstanceInfoFactory : Setting initial instance status as: STARTING
2019-02-23 00:31:14.357 INFO 3244 --- [ main] com.netflix.discovery.DiscoveryClient : Initializing Eureka in region us-east-1
2019-02-23 00:31:14.359 INFO 3244 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using JSON encoding codec LegacyJacksonJson
2019-02-23 00:31:14.359 INFO 3244 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using JSON decoding codec LegacyJacksonJson
2019-02-23 00:31:14.359 INFO 3244 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using XML encoding codec XStreamXml
2019-02-23 00:31:14.359 INFO 3244 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using XML decoding codec XStreamXml
2019-02-23 00:31:14.435 INFO 3244 --- [ main] c.n.d.s.r.aws.ConfigClusterResolver : Resolving eureka endpoints via configuration
2019-02-23 00:31:14.436 INFO 3244 --- [ main] com.netflix.discovery.DiscoveryClient : Disable delta property : false
2019-02-23 00:31:14.436 INFO 3244 --- [ main] com.netflix.discovery.DiscoveryClient : Single vip registry refresh property : null
2019-02-23 00:31:14.436 INFO 3244 --- [ main] com.netflix.discovery.DiscoveryClient : Force full registry fetch : false
2019-02-23 00:31:14.436 INFO 3244 --- [ main] com.netflix.discovery.DiscoveryClient : Application is null : false
2019-02-23 00:31:14.436 INFO 3244 --- [ main] com.netflix.discovery.DiscoveryClient : Registered Applications size is zero : true
2019-02-23 00:31:14.436 INFO 3244 --- [ main] com.netflix.discovery.DiscoveryClient : Application version is -1: true
2019-02-23 00:31:14.436 INFO 3244 --- [ main] com.netflix.discovery.DiscoveryClient : Getting all instance registry info from the eureka server
2019-02-23 00:31:14.439 INFO 3244 --- [ main] com.netflix.discovery.DiscoveryClient : The response status is 200
2019-02-23 00:31:14.440 INFO 3244 --- [ main] com.netflix.discovery.DiscoveryClient : Starting heartbeat executor: renew interval is: 30
2019-02-23 00:31:14.441 INFO 3244 --- [ main] c.n.discovery.InstanceInfoReplicator : InstanceInfoReplicator onDemand update allowed rate per min is 4
2019-02-23 00:31:14.442 INFO 3244 --- [ main] com.netflix.discovery.DiscoveryClient : Discovery Client initialized at timestamp 1550853074442 with initial instances count: 4
2019-02-23 00:31:14.443 INFO 3244 --- [ main] o.s.c.n.e.s.EurekaServiceRegistry : Registering application svcA with eureka with status UP
2019-02-23 00:31:14.443 INFO 3244 --- [ main] com.netflix.discovery.DiscoveryClient : Saw local status change event StatusChangeEvent [timestamp=1550853074443, current=UP, previous=STARTING]
2019-02-23 00:31:14.444 INFO 3244 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_SVCA/YanWei:svcA:8087: registering service...
2019-02-23 00:31:14.466 INFO 3244 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_SVCA/YanWei:svcA:8087 - registration status: 204
2019-02-23 00:31:14.469 INFO 3244 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8087 (http) with context path ''
2019-02-23 00:31:14.471 INFO 3244 --- [ main] com.yan.ClientAApplication : Started ClientAApplication in 4.293 seconds (JVM running for 4.981)
可以看到,其读取配置的URL发生了改变,集成之前,默认访问http://localhost:8888
,而此时,访问地址变成了 http://YanWei:8881/
,并且正确读取了端口号8087,这说明我们的Eureka集成成功了.