简介

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*

测试

  1. 启动eureka
  2. 启动config-server
  3. 启动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集成成功了.

Spring-Cloud-Config学习笔记(一):使用本地存储的更多相关文章

  1. spring cloud(学习笔记)高可用注册中心(Eureka)的实现(二)

    绪论 前几天我用一种方式实现了spring cloud的高可用,达到两个注册中心,详情见spring cloud(学习笔记)高可用注册中心(Eureka)的实现(一),今天我意外发现,注册中心可以无限 ...

  2. Spring Cloud Alibaba学习笔记(22) - Nacos配置管理

    目前业界流行的统一配置管理中心组件有Spring Cloud Config.Spring Cloud Alibaba的Nacos及携程开源的Apollo,本文将介绍Nacos作为统一配置管理中心的使用 ...

  3. Spring Cloud Alibaba学习笔记(1) - 整合Spring Cloud Alibaba

    Spring Cloud Alibaba从孵化器版本毕业:https://github.com/alibaba/spring-cloud-alibaba,记录一下自己学习Spring Cloud Al ...

  4. Spring Cloud Alibaba学习笔记(20) - Spring Cloud Gateway 内置的全局过滤器

    参考:https://cloud.spring.io/spring-cloud-static/Greenwich.SR2/single/spring-cloud.html#_global_filter ...

  5. Spring Cloud Alibaba学习笔记

    引自B站楠哥:https://space.bilibili.com/434617924 一.创建父工程 创建父工程hello-spring-cloud-alibaba Spring Cloud Ali ...

  6. spring cloud(学习笔记)高可用注册中心(Eureka)的实现(一)

    最近在学习的时候,发现微服务架构中,假如只有一个注册中心,那这个注册中心挂了可怎么办,这样的系统,既不安全,稳定性也不好,网上和书上找了一会,发现这个spring cloud早就想到了,并帮我们解决了 ...

  7. Spring Cloud Alibaba学习笔记(3) - Ribbon

    1.手写一个客户端负载均衡器 在了解什么是Ribbon之前,首先通过代码的方式手写一个负载均衡器 RestTemplate restTemplate = new RestTemplate(); // ...

  8. Spring Cloud Alibaba学习笔记(23) - 调用链监控工具Spring Cloud Sleuth + Zipkin

    随着业务发展,系统拆分导致系统调用链路愈发复杂一个前端请求可能最终需要调用很多次后端服务才能完成,当整个请求陷入性能瓶颈或不可用时,我们是无法得知该请求是由某个或某些后端服务引起的,这时就需要解决如何 ...

  9. Spring Cloud Alibaba学习笔记(19) - Spring Cloud Gateway 自定义过滤器工厂

    在前文中,我们介绍了Spring Cloud Gateway内置了一系列的内置过滤器工厂,若Spring Cloud Gateway内置的过滤器工厂无法满足我们的业务需求,那么此时就需要自定义自己的过 ...

  10. Spring Cloud Alibaba学习笔记(17) - Spring Cloud Gateway 自定义路由谓词工厂

    在前文中,我们介绍了Spring Cloud Gateway内置了一系列的路由谓词工厂,但是如果这些内置的路由谓词工厂不能满足业务需求的话,我们可以自定义路由谓词工厂来实现特定的需求. 例如有某个服务 ...

随机推荐

  1. SwipeableFlatList 实现类似于QQ列表滑动

    import React, { Component } from "react"; import { FlatList, RefreshControl, StyleSheet, T ...

  2. BZOJ3655 : 神经错乱数

    注意到前3个操作都不会影响每列的情况,而第4个操作必然会将行列交换,故只要每行的和相同即可满足条件. 考虑数位DP,设$f[i][j][k][t]$表示考虑最高的$i$位,第一行的和是$j$,当前行的 ...

  3. Perfect Service [POJ 3398]

    Perfect Service 描述 网络由N个通过N-1个通信链路连接的计算机组成,使得任何两台计算机可以通过独特的路由进行通信.如果两台计算机之间存在通信链路,则称这两台计算机是相邻的.计算机的邻 ...

  4. R图表入门

    R图表入门 R语言最强的功能就是统计和作图了,在学习了基本语法之后,博主马上体验了一下R的图表功能 条形图 例1 H = c(7,12,28,3,41) M = c("Mar",& ...

  5. jmeter接口测试-文件下载

    http://imgsrc.baidu.com/forum/pic/item/a89b033b5bb5c9ea901d1997dd39b6003bf3b3dc.jpg    网上找了一张高圆圆的图片 ...

  6. poj3614 Sunscreen(贪心+STL)

    https://vjudge.net/problem/POJ-3614 如果这不是优先队列专题里的,我可能不一定能想到这么做. 结构体命名得有点不好,解题中看着Edge这个不恰当的命名,思路老是断掉. ...

  7. Gradle sync failed: /Applications/Android Studio.app/Contents/gradle/gradle-2.14.1/lib/plugins/gradle-diagnostics-2.14.1.jar (No such file or directory) Consult IDE log for more details (Help | Sh

    上面出现的错误是,我从Android Studio 2.2 升级到2.3后,出现的问题, 找到方法: http://stackoverflow.com/questions/30526613/andro ...

  8. GoAccess日志分析工具

    1.1 GoAccess简介 GoAccess是一个非常良心的开源软件,它的良心之处体现在如下方面: 1)安装简单: 2)操作容易: 3)界面酷炫: GoAccess 官网 https://goacc ...

  9. IntelliJ IDEA web项目 工程构建运行部署

  10. 一个简单的开源PHP爬虫框架『Phpfetcher』

    这篇文章首发在吹水小镇:http://blog.reetsee.com/archives/366 要在手机或者电脑看到更好的图片或代码欢迎到博文原地址.也欢迎到博文原地址批评指正. 转载请注明: 吹水 ...