Spring-Cloud-Config学习笔记(一):使用本地存储

Spring Cloud Config为分布式系统中的外部配置提供服务器和客户端支持。使用Config Server,您可以为所有环境中的应用程序管理其外部属性。它非常适合spring应用,也可以使用在其他语言的应用上。
随着应用程序通过从开发到测试和生产的部署流程,您可以管理这些环境之间的配置,并确定应用程序具有迁移时需要运行的一切。
服务器存储后端的默认实现使用git,因此它轻松支持标签版本的配置环境,以及可以访问用于管理内容的各种工具。

  • HTTP,为外部配置提供基于资源的API(键值对,或者等价的YAML内容)
  • 属性值的加密和解密(对称加密和非对称加密)
  • 通过使用@EnableConfigServer在Spring boot应用中非常简单的嵌入。

  • 绑定Config服务端,并使用远程的属性源初始化Spring环境。

  • 属性值的加密和解密(对称加密和非对称加密)

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>
    </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);
    }
}
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}.properties < code></--->

由于我们没有使用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>
    </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>
    </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*

查看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集成成功了.

Original: https://www.cnblogs.com/yw0219/p/10421160.html
Author: 舒山
Title: Spring-Cloud-Config学习笔记(一):使用本地存储

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/541368/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

  • spring 定时任务@Scheduled

    1、配置文件

    Java 2023年5月30日
    047
  • 树莓派修改分辨率

    树莓派屏幕分辨率设置 树莓派一般第一次开机会自动给显示屏分配一个最合适的分辨率,但是有时候可能有个别显示屏会不兼容,就需要通过以下方式修改分辨率。而当我们使用VNC远程桌面登录的时…

    Java 2023年5月30日
    089
  • idea使用教程-常用快捷键

    【1】创建内容:alt+insert【2】main方法:psvm【3】输出语句:sout【4】复制行:ctrl+d【5】删除行:ctrl+y 【6】代码向上/下移动:Ctrl + …

    Java 2023年6月5日
    071
  • JDK成长记12:ThreadLocal (下)

    上一节你弄懂了ThreadLocal是什么、它的基本使用方式、get方法的底层原理。这一节让继续深入研究下: ThreadLocal的set源码原理 JVM的中的强引用、弱引用、软…

    Java 2023年6月5日
    082
  • Springboot整合Redis简单应用

    依赖: application配置文件: 新建RedisConfig配置文件进行redis序列化配置: 对比较常用的数据查询操作增加redis缓存: 在进行更新或者删除操作时加上对…

    Java 2023年6月7日
    066
  • HTML页面打印

    <style media=print>.Noprint{display:none;}style> <object id="WebBrowser&q…

    Java 2023年6月16日
    067
  • Redis进阶知识一览

    Redis的持久化机制 RDB: Redis DataBase 什么是RDB RDB∶每隔一段时间,把内存中的数据写入磁盘的临时文件,作为快照,恢复的时候把快照文件读进内存。如果宕…

    Java 2023年6月5日
    071
  • MarkDown Day001

    博客园 :当前访问的博文已被密码保护 请输入阅读密码: Original: https://www.cnblogs.com/shiguangzheng/p/14750559.htm…

    Java 2023年6月14日
    083
  • 微服务SpringCloud之Spring Cloud Config配置中心SVN

    在回来的路上看到一个个的都抱着花,吃了一路的狗粮,原本想着去旁边的工业园里跑跑步呢,想想还是算了,人家过七夕,俺们过巴西。上一博客学习了Spring Cloud Config使用g…

    Java 2023年5月30日
    076
  • Java Socket网络编程常见异常(转)

    4.java.net.SocketException:Socket is closed 该异常在客户端和服务器端均可能发生。异常的原因是己方主动关闭了连接后 (调用了Socket的…

    Java 2023年5月29日
    090
  • Linux下Oracle单实例配置多监听

    Oracle单实例配置多监听 一、前言 有时候我们项目中需要使用Oracle数据库,同时要需要不同的数据源,而Oracle不像Mysql那样直接建个库即可,Oracle是以账号为单…

    Java 2023年6月8日
    077
  • java入门基础 static final 关键字 修饰符 解释(通俗易懂)

    final 和 static和 final static 区别解释? static是用来修饰静态资源的(包括类、方法、变量等),final 是用来保证当前变量为常量,final s…

    Java 2023年6月7日
    075
  • Spring ClassPathResource

    Spring ClassPathResource ClassPathResource用于加载资源文件,如果类路径资源文件位于文件系统中,支持解析为File,但是不用于JAR中的资源…

    Java 2023年6月7日
    079
  • CAS 入门实战(4)–自定义登录页面

    CAS 默认的登录页面显然不适合实际的使用,本文主要介绍如何自定义登录页面;文中使用到的软件版本:JDK 1.8.0_191、Tomcat 8.5.76、CAS 5.3.16。 1…

    Java 2023年6月16日
    084
  • Centos7 编译安装Nginx

    升级系统所有软件 yum -y update 安装Nginx编译所需要的依赖项 yum -y install gcc gcc-c++ make zlib-devel pcre-de…

    Java 2023年5月30日
    057
  • Spring AOP

    一、AOP的概念 1、AOP:面向切面编程,利用AOP可以对业务逻辑的各个部分进行隔离,从而使得业务逻辑各个部分的耦合度降低。提高程序的可重用性,同时提高了开发效率 2、AOP通俗…

    Java 2023年6月7日
    063
亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球