spring cloud config入门,spring cloud config git配置配置中心
发布日期:2021-05-07 13:21:54 浏览次数:23 分类:原创文章

本文共 32017 字,大约阅读时间需要 106 分钟。

之前进行了spring config配置中心基于本地文件的示例,spring cloud config还提供供了基于git的配置中心,下面讲解spring cloud config git的入门示例。
本次演示采用的springboot版本是2.1.3.RELEASE,spring cloud版本是Greenwich.SR2.
首先建立config-server-git模块,引入必要的pom依赖:

<?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">    <parent>        <artifactId>spring-cloud-test-001</artifactId>        <groupId>com.leo.test</groupId>        <version>1.0.0-snapshot</version>    </parent>    <modelVersion>4.0.0</modelVersion>    <artifactId>config-server-git</artifactId>    <dependencies>        <dependency>            <groupId>org.springframework.boot</groupId>            <artifactId>spring-boot-starter-web</artifactId>        </dependency>        <dependency>            <groupId>org.springframework.cloud</groupId>            <artifactId>spring-cloud-config-server</artifactId>        </dependency>    </dependencies>    <build>        <plugins>            <plugin>                <groupId>org.springframework.boot</groupId>                <artifactId>spring-boot-maven-plugin</artifactId>            </plugin>        </plugins>    </build></project>

建立模块配置文件,如下:

#注意是 application.ymlspring:  profiles:    active: remote  cloud:    config:      server:        git:          uri: https://github.com/hanxueming126/open-config-source          search-paths: config          username:           password:           default-label: develop          force-pull: true #本地与git有冲突时,强制拉取覆盖本地  application:    name: config-server-gitserver:  port: 9060management:  endpoints:    web:      exposure:        include: "*"#debug: true

编写启动类,如下:

import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.config.server.EnableConfigServer;@SpringBootApplication@EnableConfigServerpublic class ConfigServerGitApplication {     public static void main(String[] args) {        SpringApplication.run(ConfigServerGitApplication.class);    }}

这样config-server-git模块开发完成
接下来开发spring cloud config配置中心客户端,与本地配置的客户端的一样:
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">    <parent>        <artifactId>spring-cloud-test-001</artifactId>        <groupId>com.leo.test</groupId>        <version>1.0.0-snapshot</version>    </parent>    <modelVersion>4.0.0</modelVersion>    <artifactId>config-consumer-001</artifactId>    <dependencies>        <dependency>            <groupId>org.springframework.boot</groupId>            <artifactId>spring-boot-starter-web</artifactId>        </dependency>        <dependency>            <groupId>org.springframework.cloud</groupId>            <artifactId>spring-cloud-starter-config</artifactId>        </dependency>    </dependencies>    <build>        <plugins>            <plugin>                <groupId>org.springframework.boot</groupId>                <artifactId>spring-boot-maven-plugin</artifactId>            </plugin>        </plugins>    </build></project>

编写配置中心客户端配置文件bootstrap.yml:

#注意是 bootstrap.ymlspring:  application:    name: config-consumer-001  cloud:    config:      uri: http://localhost:9060      fail-fast: true  profiles:    active: devmanagement:  endpoints:    web:      exposure:        include: '*'#debug: true

建立controler:

import org.springframework.beans.factory.annotation.Value;import org.springframework.cloud.context.config.annotation.RefreshScope;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;@RestController@RequestMapping("/config/consumer")@RefreshScopepublic class ConsumerController {    @Value("${hello}")    private String hello;    @RequestMapping("/test")    public String testConfig(){        return String.format("hello is %s ",hello);    }}

建立启动类:

import org.springframework.beans.factory.annotation.Value;import org.springframework.cloud.context.config.annotation.RefreshScope;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;@RestController@RequestMapping("/config/consumer")@RefreshScopepublic class ConsumerController {    @Value("${hello}")    private String hello;    @RequestMapping("/test")    public String testConfig(){        return String.format("hello is %s ",hello);    }}

启动config-servedr-git:

"D:\develop tool\jdk1.8.0_151\bin\java.exe" -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true "-javaagent:D:\develop tool\ideaIU-2019.3.4.win\lib\idea_rt.jar=63030:D:\develop tool\ideaIU-2019.3.4.win\bin" -Dfile.encoding=UTF-8 -classpath "D:\develop tool\jdk1.8.0_151\jre\lib\charsets.jar;D:\develop tool\jdk1.8.0_151\jre\lib\deploy.jar;D:\develop tool\jdk1.8.0_151\jre\lib\ext\access-bridge-64.jar;D:\develop tool\jdk1.8.0_151\jre\lib\ext\cldrdata.jar;D:\develop tool\jdk1.8.0_151\jre\lib\ext\dnsns.jar;D:\develop tool\jdk1.8.0_151\jre\lib\ext\jaccess.jar;D:\develop tool\jdk1.8.0_151\jre\lib\ext\jfxrt.jar;D:\develop tool\jdk1.8.0_151\jre\lib\ext\localedata.jar;D:\develop tool\jdk1.8.0_151\jre\lib\ext\nashorn.jar;D:\develop tool\jdk1.8.0_151\jre\lib\ext\sunec.jar;D:\develop tool\jdk1.8.0_151\jre\lib\ext\sunjce_provider.jar;D:\develop tool\jdk1.8.0_151\jre\lib\ext\sunmscapi.jar;D:\develop tool\jdk1.8.0_151\jre\lib\ext\sunpkcs11.jar;D:\develop tool\jdk1.8.0_151\jre\lib\ext\zipfs.jar;D:\develop tool\jdk1.8.0_151\jre\lib\javaws.jar;D:\develop tool\jdk1.8.0_151\jre\lib\jce.jar;D:\develop tool\jdk1.8.0_151\jre\lib\jfr.jar;D:\develop tool\jdk1.8.0_151\jre\lib\jfxswt.jar;D:\develop tool\jdk1.8.0_151\jre\lib\jsse.jar;D:\develop tool\jdk1.8.0_151\jre\lib\management-agent.jar;D:\develop tool\jdk1.8.0_151\jre\lib\plugin.jar;D:\develop tool\jdk1.8.0_151\jre\lib\resources.jar;D:\develop tool\jdk1.8.0_151\jre\lib\rt.jar;D:\data\github\leo-test-all\spring-cloud-test-all\spring-cloud-test-001\config-server-git\target\classes;C:\Users\T470\.m2\repository\org\springframework\boot\spring-boot-starter-web\2.1.3.RELEASE\spring-boot-starter-web-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\boot\spring-boot-starter\2.1.3.RELEASE\spring-boot-starter-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\boot\spring-boot\2.1.3.RELEASE\spring-boot-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\boot\spring-boot-autoconfigure\2.1.3.RELEASE\spring-boot-autoconfigure-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\boot\spring-boot-starter-logging\2.1.3.RELEASE\spring-boot-starter-logging-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;C:\Users\T470\.m2\repository\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;C:\Users\T470\.m2\repository\org\apache\logging\log4j\log4j-to-slf4j\2.11.2\log4j-to-slf4j-2.11.2.jar;C:\Users\T470\.m2\repository\org\apache\logging\log4j\log4j-api\2.11.2\log4j-api-2.11.2.jar;C:\Users\T470\.m2\repository\org\slf4j\jul-to-slf4j\1.7.25\jul-to-slf4j-1.7.25.jar;C:\Users\T470\.m2\repository\javax\annotation\javax.annotation-api\1.3.2\javax.annotation-api-1.3.2.jar;C:\Users\T470\.m2\repository\org\springframework\spring-core\5.1.5.RELEASE\spring-core-5.1.5.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\spring-jcl\5.1.5.RELEASE\spring-jcl-5.1.5.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\boot\spring-boot-starter-json\2.1.3.RELEASE\spring-boot-starter-json-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.9.8\jackson-databind-2.9.8.jar;C:\Users\T470\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.9.8\jackson-core-2.9.8.jar;C:\Users\T470\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.9.8\jackson-datatype-jdk8-2.9.8.jar;C:\Users\T470\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.9.8\jackson-datatype-jsr310-2.9.8.jar;C:\Users\T470\.m2\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.9.8\jackson-module-parameter-names-2.9.8.jar;C:\Users\T470\.m2\repository\org\springframework\boot\spring-boot-starter-tomcat\2.1.3.RELEASE\spring-boot-starter-tomcat-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\org\apache\tomcat\embed\tomcat-embed-core\9.0.16\tomcat-embed-core-9.0.16.jar;C:\Users\T470\.m2\repository\org\apache\tomcat\embed\tomcat-embed-el\9.0.16\tomcat-embed-el-9.0.16.jar;C:\Users\T470\.m2\repository\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.16\tomcat-embed-websocket-9.0.16.jar;C:\Users\T470\.m2\repository\org\hibernate\validator\hibernate-validator\6.0.14.Final\hibernate-validator-6.0.14.Final.jar;C:\Users\T470\.m2\repository\javax\validation\validation-api\2.0.1.Final\validation-api-2.0.1.Final.jar;C:\Users\T470\.m2\repository\org\jboss\logging\jboss-logging\3.3.2.Final\jboss-logging-3.3.2.Final.jar;C:\Users\T470\.m2\repository\com\fasterxml\classmate\1.4.0\classmate-1.4.0.jar;C:\Users\T470\.m2\repository\org\springframework\spring-web\5.1.5.RELEASE\spring-web-5.1.5.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\spring-beans\5.1.5.RELEASE\spring-beans-5.1.5.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\spring-webmvc\5.1.5.RELEASE\spring-webmvc-5.1.5.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\spring-aop\5.1.5.RELEASE\spring-aop-5.1.5.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\spring-context\5.1.5.RELEASE\spring-context-5.1.5.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\spring-expression\5.1.5.RELEASE\spring-expression-5.1.5.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\cloud\spring-cloud-config-server\2.1.3.RELEASE\spring-cloud-config-server-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\cloud\spring-cloud-config-client\2.1.3.RELEASE\spring-cloud-config-client-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\cloud\spring-cloud-commons\2.1.2.RELEASE\spring-cloud-commons-2.1.2.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\cloud\spring-cloud-context\2.1.2.RELEASE\spring-cloud-context-2.1.2.RELEASE.jar;C:\Users\T470\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.9.0\jackson-annotations-2.9.0.jar;C:\Users\T470\.m2\repository\org\springframework\boot\spring-boot-starter-actuator\2.1.3.RELEASE\spring-boot-starter-actuator-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\boot\spring-boot-actuator-autoconfigure\2.1.3.RELEASE\spring-boot-actuator-autoconfigure-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\boot\spring-boot-actuator\2.1.3.RELEASE\spring-boot-actuator-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\io\micrometer\micrometer-core\1.1.3\micrometer-core-1.1.3.jar;C:\Users\T470\.m2\repository\org\hdrhistogram\HdrHistogram\2.1.9\HdrHistogram-2.1.9.jar;C:\Users\T470\.m2\repository\org\latencyutils\LatencyUtils\2.0.3\LatencyUtils-2.0.3.jar;C:\Users\T470\.m2\repository\org\springframework\security\spring-security-crypto\5.1.4.RELEASE\spring-security-crypto-5.1.4.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\security\spring-security-rsa\1.0.7.RELEASE\spring-security-rsa-1.0.7.RELEASE.jar;C:\Users\T470\.m2\repository\org\bouncycastle\bcpkix-jdk15on\1.60\bcpkix-jdk15on-1.60.jar;C:\Users\T470\.m2\repository\org\bouncycastle\bcprov-jdk15on\1.60\bcprov-jdk15on-1.60.jar;C:\Users\T470\.m2\repository\org\eclipse\jgit\org.eclipse.jgit\5.1.3.201810200350-r\org.eclipse.jgit-5.1.3.201810200350-r.jar;C:\Users\T470\.m2\repository\com\jcraft\jsch\0.1.54\jsch-0.1.54.jar;C:\Users\T470\.m2\repository\com\jcraft\jzlib\1.1.1\jzlib-1.1.1.jar;C:\Users\T470\.m2\repository\com\googlecode\javaewah\JavaEWAH\1.1.6\JavaEWAH-1.1.6.jar;C:\Users\T470\.m2\repository\org\slf4j\slf4j-api\1.7.25\slf4j-api-1.7.25.jar;C:\Users\T470\.m2\repository\org\eclipse\jgit\org.eclipse.jgit.http.apache\5.1.3.201810200350-r\org.eclipse.jgit.http.apache-5.1.3.201810200350-r.jar;C:\Users\T470\.m2\repository\org\apache\httpcomponents\httpclient\4.5.7\httpclient-4.5.7.jar;C:\Users\T470\.m2\repository\commons-codec\commons-codec\1.11\commons-codec-1.11.jar;C:\Users\T470\.m2\repository\org\apache\httpcomponents\httpcore\4.4.11\httpcore-4.4.11.jar;C:\Users\T470\.m2\repository\org\yaml\snakeyaml\1.23\snakeyaml-1.23.jar" com.leo.test.spring.cloud.test.config.server.git.ConfigServerGitApplication2020-05-22 22:34:42.493  INFO 5556 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$464605d8] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)  .   ____          _            __ _ _ /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/  ___)| |_)| | | | | || (_| |  ) ) ) )  '  |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot ::        (v2.1.3.RELEASE)2020-05-22 22:34:43.219  INFO 5556 --- [           main] t.s.c.t.c.s.g.ConfigServerGitApplication : The following profiles are active: remote2020-05-22 22:34:43.933  INFO 5556 --- [           main] o.s.cloud.context.scope.GenericScope     : BeanFactory id=b6fbcdbd-681b-3072-9162-61d114dc5e692020-05-22 22:34:43.954  INFO 5556 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$464605d8] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)2020-05-22 22:34:44.176  INFO 5556 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 9060 (http)2020-05-22 22:34:44.197  INFO 5556 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]2020-05-22 22:34:44.197  INFO 5556 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.16]2020-05-22 22:34:44.204  INFO 5556 --- [           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:\develop tool\jdk1.8.0_151\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;D:\develop tool\python36\Scripts\;D:\develop tool\python36\;D:\develop tool\scala-2.12.8\bin;C:\Program Files\Intel\iCLS Client\;D:\tool\scala-2.10.4\bin;D:\develop tool\hadoop-2.6.5\bin;D:\develop tool\gradle-5.5.1\bin;D:\develop tool\protoc-3.6.1-win32\bin;C:\nwrfcsdk\lib;C:\nwrfcsdk\include;C:\Program Files\IBM\clidriver\bin;D:\tool\mingw64\bin;D:\develop tool\GOPATH\bin;D:\develop tool\GOROOT\go-1.11\bin;D:\develop tool\mysql-5.6.41-winx64\bin;D:\develop tool\apache-maven-3.5.4/bin;C:\Program Files (x86)\Common Files\NetSarang;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\OpenVPN\bin;D:\develop tool\jdk1.8.0_151/bin;C:\Program Files\Git\cmd;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\dotnet\;D:\Program Files\TortoiseSVN\bin;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)\Common Files\Thunder Network\KanKan\Codecs;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;D:\develop tool\apache-ant-1.9.14\bin;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Users\T470\AppData\Local\Programs\Fiddler;.]2020-05-22 22:34:44.324  INFO 5556 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext2020-05-22 22:34:44.325  INFO 5556 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1092 ms2020-05-22 22:34:45.353  INFO 5556 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'2020-05-22 22:34:46.082  INFO 5556 --- [           main] o.s.b.a.e.web.EndpointLinksResolver      : Exposing 17 endpoint(s) beneath base path '/actuator'2020-05-22 22:34:46.188  INFO 5556 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 9060 (http) with context path ''2020-05-22 22:34:46.189  INFO 5556 --- [           main] t.s.c.t.c.s.g.ConfigServerGitApplication : Started ConfigServerGitApplication in 5.887 seconds (JVM running for 7.107)2020-05-22 22:34:46.629  INFO 5556 --- [169.254.218.126] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'2020-05-22 22:34:46.630  INFO 5556 --- [169.254.218.126] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'2020-05-22 22:34:46.639  INFO 5556 --- [169.254.218.126] o.s.web.servlet.DispatcherServlet        : Completed initialization in 9 ms

启动spring cloud config consumer端:

"D:\develop tool\jdk1.8.0_151\bin\java.exe" -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true "-javaagent:D:\develop tool\ideaIU-2019.3.4.win\lib\idea_rt.jar=63059:D:\develop tool\ideaIU-2019.3.4.win\bin" -Dfile.encoding=UTF-8 -classpath "D:\develop tool\jdk1.8.0_151\jre\lib\charsets.jar;D:\develop tool\jdk1.8.0_151\jre\lib\deploy.jar;D:\develop tool\jdk1.8.0_151\jre\lib\ext\access-bridge-64.jar;D:\develop tool\jdk1.8.0_151\jre\lib\ext\cldrdata.jar;D:\develop tool\jdk1.8.0_151\jre\lib\ext\dnsns.jar;D:\develop tool\jdk1.8.0_151\jre\lib\ext\jaccess.jar;D:\develop tool\jdk1.8.0_151\jre\lib\ext\jfxrt.jar;D:\develop tool\jdk1.8.0_151\jre\lib\ext\localedata.jar;D:\develop tool\jdk1.8.0_151\jre\lib\ext\nashorn.jar;D:\develop tool\jdk1.8.0_151\jre\lib\ext\sunec.jar;D:\develop tool\jdk1.8.0_151\jre\lib\ext\sunjce_provider.jar;D:\develop tool\jdk1.8.0_151\jre\lib\ext\sunmscapi.jar;D:\develop tool\jdk1.8.0_151\jre\lib\ext\sunpkcs11.jar;D:\develop tool\jdk1.8.0_151\jre\lib\ext\zipfs.jar;D:\develop tool\jdk1.8.0_151\jre\lib\javaws.jar;D:\develop tool\jdk1.8.0_151\jre\lib\jce.jar;D:\develop tool\jdk1.8.0_151\jre\lib\jfr.jar;D:\develop tool\jdk1.8.0_151\jre\lib\jfxswt.jar;D:\develop tool\jdk1.8.0_151\jre\lib\jsse.jar;D:\develop tool\jdk1.8.0_151\jre\lib\management-agent.jar;D:\develop tool\jdk1.8.0_151\jre\lib\plugin.jar;D:\develop tool\jdk1.8.0_151\jre\lib\resources.jar;D:\develop tool\jdk1.8.0_151\jre\lib\rt.jar;D:\data\github\leo-test-all\spring-cloud-test-all\spring-cloud-test-001\config-consumer-001\target\classes;C:\Users\T470\.m2\repository\org\springframework\boot\spring-boot-starter-web\2.1.3.RELEASE\spring-boot-starter-web-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\boot\spring-boot-starter\2.1.3.RELEASE\spring-boot-starter-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\boot\spring-boot\2.1.3.RELEASE\spring-boot-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\boot\spring-boot-autoconfigure\2.1.3.RELEASE\spring-boot-autoconfigure-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\boot\spring-boot-starter-logging\2.1.3.RELEASE\spring-boot-starter-logging-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;C:\Users\T470\.m2\repository\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;C:\Users\T470\.m2\repository\org\slf4j\slf4j-api\1.7.25\slf4j-api-1.7.25.jar;C:\Users\T470\.m2\repository\org\apache\logging\log4j\log4j-to-slf4j\2.11.2\log4j-to-slf4j-2.11.2.jar;C:\Users\T470\.m2\repository\org\apache\logging\log4j\log4j-api\2.11.2\log4j-api-2.11.2.jar;C:\Users\T470\.m2\repository\org\slf4j\jul-to-slf4j\1.7.25\jul-to-slf4j-1.7.25.jar;C:\Users\T470\.m2\repository\javax\annotation\javax.annotation-api\1.3.2\javax.annotation-api-1.3.2.jar;C:\Users\T470\.m2\repository\org\springframework\spring-core\5.1.5.RELEASE\spring-core-5.1.5.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\spring-jcl\5.1.5.RELEASE\spring-jcl-5.1.5.RELEASE.jar;C:\Users\T470\.m2\repository\org\yaml\snakeyaml\1.23\snakeyaml-1.23.jar;C:\Users\T470\.m2\repository\org\springframework\boot\spring-boot-starter-json\2.1.3.RELEASE\spring-boot-starter-json-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.9.8\jackson-datatype-jdk8-2.9.8.jar;C:\Users\T470\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.9.8\jackson-datatype-jsr310-2.9.8.jar;C:\Users\T470\.m2\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.9.8\jackson-module-parameter-names-2.9.8.jar;C:\Users\T470\.m2\repository\org\springframework\boot\spring-boot-starter-tomcat\2.1.3.RELEASE\spring-boot-starter-tomcat-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\org\apache\tomcat\embed\tomcat-embed-core\9.0.16\tomcat-embed-core-9.0.16.jar;C:\Users\T470\.m2\repository\org\apache\tomcat\embed\tomcat-embed-el\9.0.16\tomcat-embed-el-9.0.16.jar;C:\Users\T470\.m2\repository\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.16\tomcat-embed-websocket-9.0.16.jar;C:\Users\T470\.m2\repository\org\hibernate\validator\hibernate-validator\6.0.14.Final\hibernate-validator-6.0.14.Final.jar;C:\Users\T470\.m2\repository\javax\validation\validation-api\2.0.1.Final\validation-api-2.0.1.Final.jar;C:\Users\T470\.m2\repository\org\jboss\logging\jboss-logging\3.3.2.Final\jboss-logging-3.3.2.Final.jar;C:\Users\T470\.m2\repository\com\fasterxml\classmate\1.4.0\classmate-1.4.0.jar;C:\Users\T470\.m2\repository\org\springframework\spring-web\5.1.5.RELEASE\spring-web-5.1.5.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\spring-beans\5.1.5.RELEASE\spring-beans-5.1.5.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\spring-webmvc\5.1.5.RELEASE\spring-webmvc-5.1.5.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\spring-aop\5.1.5.RELEASE\spring-aop-5.1.5.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\spring-context\5.1.5.RELEASE\spring-context-5.1.5.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\spring-expression\5.1.5.RELEASE\spring-expression-5.1.5.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\cloud\spring-cloud-starter-config\2.1.3.RELEASE\spring-cloud-starter-config-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\cloud\spring-cloud-starter\2.1.2.RELEASE\spring-cloud-starter-2.1.2.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\cloud\spring-cloud-context\2.1.2.RELEASE\spring-cloud-context-2.1.2.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\security\spring-security-crypto\5.1.4.RELEASE\spring-security-crypto-5.1.4.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\cloud\spring-cloud-commons\2.1.2.RELEASE\spring-cloud-commons-2.1.2.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\security\spring-security-rsa\1.0.7.RELEASE\spring-security-rsa-1.0.7.RELEASE.jar;C:\Users\T470\.m2\repository\org\bouncycastle\bcpkix-jdk15on\1.60\bcpkix-jdk15on-1.60.jar;C:\Users\T470\.m2\repository\org\bouncycastle\bcprov-jdk15on\1.60\bcprov-jdk15on-1.60.jar;C:\Users\T470\.m2\repository\org\springframework\cloud\spring-cloud-config-client\2.1.3.RELEASE\spring-cloud-config-client-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.9.0\jackson-annotations-2.9.0.jar;C:\Users\T470\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.9.8\jackson-databind-2.9.8.jar;C:\Users\T470\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.9.8\jackson-core-2.9.8.jar;C:\Users\T470\.m2\repository\org\springframework\boot\spring-boot-starter-actuator\2.1.3.RELEASE\spring-boot-starter-actuator-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\boot\spring-boot-actuator-autoconfigure\2.1.3.RELEASE\spring-boot-actuator-autoconfigure-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\boot\spring-boot-actuator\2.1.3.RELEASE\spring-boot-actuator-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\io\micrometer\micrometer-core\1.1.3\micrometer-core-1.1.3.jar;C:\Users\T470\.m2\repository\org\hdrhistogram\HdrHistogram\2.1.9\HdrHistogram-2.1.9.jar;C:\Users\T470\.m2\repository\org\latencyutils\LatencyUtils\2.0.3\LatencyUtils-2.0.3.jar" com.leo.test.spring.cloud.test.config.consumer.ConfigConsumerApplication2020-05-22 22:35:18.238  INFO 7084 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$caca00df] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)  .   ____          _            __ _ _ /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/  ___)| |_)| | | | | || (_| |  ) ) ) )  '  |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot ::        (v2.1.3.RELEASE)2020-05-22 22:35:18.870  INFO 7084 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:90602020-05-22 22:35:22.579  INFO 7084 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Located environment: name=config-consumer-001, profiles=[dev], label=null, version=67493a53e162fd0f0f953d17274c3261c33523cd, state=null2020-05-22 22:35:22.579  INFO 7084 --- [           main] b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource {name='configService', propertySources=[MapPropertySource {name='configClient'}, MapPropertySource {name='https://github.com/hanxueming126/open-config-source/config/config-consumer-001-dev.yaml'}]}2020-05-22 22:35:22.582  INFO 7084 --- [           main] .l.t.s.c.t.c.c.ConfigConsumerApplication : The following profiles are active: dev2020-05-22 22:35:23.188  INFO 7084 --- [           main] o.s.cloud.context.scope.GenericScope     : BeanFactory id=3d53c625-f39f-3206-ba2a-c3072e301c8a2020-05-22 22:35:23.208  INFO 7084 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$caca00df] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)2020-05-22 22:35:23.420  INFO 7084 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 9080 (http)2020-05-22 22:35:23.438  INFO 7084 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]2020-05-22 22:35:23.438  INFO 7084 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.16]2020-05-22 22:35:23.444  INFO 7084 --- [           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:\develop tool\jdk1.8.0_151\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;D:\develop tool\python36\Scripts\;D:\develop tool\python36\;D:\develop tool\scala-2.12.8\bin;C:\Program Files\Intel\iCLS Client\;D:\tool\scala-2.10.4\bin;D:\develop tool\hadoop-2.6.5\bin;D:\develop tool\gradle-5.5.1\bin;D:\develop tool\protoc-3.6.1-win32\bin;C:\nwrfcsdk\lib;C:\nwrfcsdk\include;C:\Program Files\IBM\clidriver\bin;D:\tool\mingw64\bin;D:\develop tool\GOPATH\bin;D:\develop tool\GOROOT\go-1.11\bin;D:\develop tool\mysql-5.6.41-winx64\bin;D:\develop tool\apache-maven-3.5.4/bin;C:\Program Files (x86)\Common Files\NetSarang;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\OpenVPN\bin;D:\develop tool\jdk1.8.0_151/bin;C:\Program Files\Git\cmd;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\dotnet\;D:\Program Files\TortoiseSVN\bin;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)\Common Files\Thunder Network\KanKan\Codecs;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;D:\develop tool\apache-ant-1.9.14\bin;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Users\T470\AppData\Local\Programs\Fiddler;.]2020-05-22 22:35:23.531  INFO 7084 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext2020-05-22 22:35:23.531  INFO 7084 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 940 ms2020-05-22 22:35:24.052  INFO 7084 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'2020-05-22 22:35:24.726  INFO 7084 --- [           main] o.s.b.a.e.web.EndpointLinksResolver      : Exposing 17 endpoint(s) beneath base path '/actuator'2020-05-22 22:35:24.817  INFO 7084 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 9080 (http) with context path ''2020-05-22 22:35:24.819  INFO 7084 --- [           main] .l.t.s.c.t.c.c.ConfigConsumerApplication : Started ConfigConsumerApplication in 9.046 seconds (JVM running for 10.031)2020-05-22 22:35:25.338  INFO 7084 --- [169.254.218.126] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'2020-05-22 22:35:25.338  INFO 7084 --- [169.254.218.126] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'2020-05-22 22:35:25.341  INFO 7084 --- [169.254.218.126] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:90602020-05-22 22:35:25.348  INFO 7084 --- [169.254.218.126] o.s.web.servlet.DispatcherServlet        : Completed initialization in 10 ms2020-05-22 22:35:28.020  INFO 7084 --- [169.254.218.126] c.c.c.ConfigServicePropertySourceLocator : Located environment: name=config-consumer-001, profiles=[dev], label=null, version=67493a53e162fd0f0f953d17274c3261c33523cd, state=null

可以看到在9080端口启动,而服务端则增加如下日志信息:

2020-05-22 22:35:22.515  INFO 5556 --- [nio-9060-exec-1] o.s.c.c.s.e.NativeEnvironmentRepository  : Adding property source: file:/C:/Users/T470/AppData/Local/Temp/config-repo-2387634544271078821/config/config-consumer-001-dev.yaml2020-05-22 22:35:28.017  INFO 5556 --- [nio-9060-exec-2] o.s.c.c.s.e.NativeEnvironmentRepository  : Adding property source: file:/C:/Users/T470/AppData/Local/Temp/config-repo-2387634544271078821/config/config-consumer-001-dev.yaml

访问: http://localhost:9080/config/consumer/test

在这里插入图片描述正确读取到了配置,完成。
这里如果用githup做配置文件测试,如果登录或者timeout,可以将配置文件单独放在一个项目里面,并设置项目为public

上一篇:spring cloud config入门,spring cloud config mysql数据库配置配置中心
下一篇:spring cloud config入门,spring cloud config native本地配置配置中心

发表评论

最新留言

感谢大佬
[***.8.128.20]2025年04月06日 14时27分23秒