博客
关于我
spring cloud config入门,spring cloud config mysql数据库配置配置中心
阅读量:341 次
发布时间:2019-03-04

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

之前进行了spring config配置中心基于本地文件和git的示例,spring cloud config还提供供了基于数据库的配置中心,下面讲解spring cloud config mysql的入门示例。
本次演示采用的springboot版本是2.1.3.RELEASE,spring cloud版本是Greenwich.SR2.
首先建立config-server-mysql模块,引入必要的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-mysql</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>        <dependency>            <groupId>mysql</groupId>            <artifactId>mysql-connector-java</artifactId>            <version>5.1.21</version>        </dependency>        <dependency>            <groupId>org.springframework.boot</groupId>            <artifactId>spring-boot-starter-jdbc</artifactId>        </dependency>        <dependency>            <groupId>org.springframework.boot</groupId>            <artifactId>spring-boot-starter-data-jpa</artifactId>        </dependency>    </dependencies>    <build>        <plugins>            <plugin>                <groupId>org.springframework.boot</groupId>                <artifactId>spring-boot-maven-plugin</artifactId>            </plugin>        </plugins>    </build></project>

建立配置文件:

spring:  profiles:    active: jdbc #这里需要指定为jdbc  datasource:    url: jdbc:mysql://xxxxx    username: xxx    password: xxxx    driver-class-name: com.mysql.jdbc.Driver  cloud:    config:      server:        jdbc:          sql: "select key1,value1 from config where application=? and profile=? and label=?"        default-label: master  application:    name: config-server-mysqlserver:  port: 9060#debug: true

对应数据库中配置表结构如下:

CREATE TABLE `config` (  `id` bigint(20) NOT NULL AUTO_INCREMENT,  `key1` varchar(500) NOT NULL,  `value1` varchar(500) NOT NULL,  `application` varchar(50) NOT NULL,  `profile` varchar(50) NOT NULL,  `label` varchar(50) DEFAULT NULL,  PRIMARY KEY (`id`))

当配置中心客户端请求时,会以 传递参数applicaitonName和profile在加上label属性在表中查找对应的配置信息
表中配置信息如下:
在这里插入图片描述
建立启动类:

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

这样配置中心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">    <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-server-mysql:

"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=53536: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-mysql\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;C:\Users\T470\.m2\repository\mysql\mysql-connector-java\5.1.21\mysql-connector-java-5.1.21.jar;C:\Users\T470\.m2\repository\org\springframework\boot\spring-boot-starter-jdbc\2.1.3.RELEASE\spring-boot-starter-jdbc-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\com\zaxxer\HikariCP\3.2.0\HikariCP-3.2.0.jar;C:\Users\T470\.m2\repository\org\springframework\spring-jdbc\5.1.5.RELEASE\spring-jdbc-5.1.5.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\spring-tx\5.1.5.RELEASE\spring-tx-5.1.5.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\boot\spring-boot-starter-data-jpa\2.1.3.RELEASE\spring-boot-starter-data-jpa-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\boot\spring-boot-starter-aop\2.1.3.RELEASE\spring-boot-starter-aop-2.1.3.RELEASE.jar;C:\Users\T470\.m2\repository\org\aspectj\aspectjweaver\1.9.2\aspectjweaver-1.9.2.jar;C:\Users\T470\.m2\repository\javax\transaction\javax.transaction-api\1.3\javax.transaction-api-1.3.jar;C:\Users\T470\.m2\repository\javax\xml\bind\jaxb-api\2.3.1\jaxb-api-2.3.1.jar;C:\Users\T470\.m2\repository\javax\activation\javax.activation-api\1.2.0\javax.activation-api-1.2.0.jar;C:\Users\T470\.m2\repository\org\hibernate\hibernate-core\5.3.7.Final\hibernate-core-5.3.7.Final.jar;C:\Users\T470\.m2\repository\javax\persistence\javax.persistence-api\2.2\javax.persistence-api-2.2.jar;C:\Users\T470\.m2\repository\org\javassist\javassist\3.23.1-GA\javassist-3.23.1-GA.jar;C:\Users\T470\.m2\repository\net\bytebuddy\byte-buddy\1.9.10\byte-buddy-1.9.10.jar;C:\Users\T470\.m2\repository\antlr\antlr\2.7.7\antlr-2.7.7.jar;C:\Users\T470\.m2\repository\org\jboss\jandex\2.0.5.Final\jandex-2.0.5.Final.jar;C:\Users\T470\.m2\repository\org\dom4j\dom4j\2.1.1\dom4j-2.1.1.jar;C:\Users\T470\.m2\repository\org\hibernate\common\hibernate-commons-annotations\5.0.4.Final\hibernate-commons-annotations-5.0.4.Final.jar;C:\Users\T470\.m2\repository\org\springframework\data\spring-data-jpa\2.1.5.RELEASE\spring-data-jpa-2.1.5.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\data\spring-data-commons\2.1.5.RELEASE\spring-data-commons-2.1.5.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\spring-orm\5.1.5.RELEASE\spring-orm-5.1.5.RELEASE.jar;C:\Users\T470\.m2\repository\org\springframework\spring-aspects\5.1.5.RELEASE\spring-aspects-5.1.5.RELEASE.jar" com.leo.test.spring.cloud.test.config.server.mysql.ConfigServerMysqlApplication2020-05-22 22:49:36.657  INFO 2916 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$dad278f3] 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:49:37.382  INFO 2916 --- [           main] s.c.t.c.s.m.ConfigServerMysqlApplication : The following profiles are active: jdbc2020-05-22 22:49:38.001  INFO 2916 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.2020-05-22 22:49:38.016  INFO 2916 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 9ms. Found 0 repository interfaces.2020-05-22 22:49:38.264  INFO 2916 --- [           main] o.s.cloud.context.scope.GenericScope     : BeanFactory id=6664eba1-1916-3dd2-9ba0-bf2bf9be10572020-05-22 22:49:38.353  INFO 2916 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$beb875f6] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)2020-05-22 22:49:38.373  INFO 2916 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$dad278f3] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)2020-05-22 22:49:38.620  INFO 2916 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 9060 (http)2020-05-22 22:49:38.638  INFO 2916 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]2020-05-22 22:49:38.638  INFO 2916 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.16]2020-05-22 22:49:38.643  INFO 2916 --- [           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:49:38.773  INFO 2916 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext2020-05-22 22:49:38.773  INFO 2916 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1381 ms2020-05-22 22:49:39.428  INFO 2916 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...2020-05-22 22:49:39.980  INFO 2916 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.2020-05-22 22:49:40.054  INFO 2916 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [	name: default	...]2020-05-22 22:49:40.109  INFO 2916 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {5.3.7.Final}2020-05-22 22:49:40.111  INFO 2916 --- [           main] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found2020-05-22 22:49:40.227  INFO 2916 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.4.Final}2020-05-22 22:49:40.349  INFO 2916 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect2020-05-22 22:49:40.496  INFO 2916 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'2020-05-22 22:49:40.709  INFO 2916 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'2020-05-22 22:49:40.742  WARN 2916 --- [           main] aWebConfiguration$JpaWebMvcConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning2020-05-22 22:49:41.644  INFO 2916 --- [           main] o.s.b.a.e.web.EndpointLinksResolver      : Exposing 2 endpoint(s) beneath base path '/actuator'2020-05-22 22:49:41.752  INFO 2916 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 9060 (http) with context path ''2020-05-22 22:49:41.753  INFO 2916 --- [           main] s.c.t.c.s.m.ConfigServerMysqlApplication : Started ConfigServerMysqlApplication in 7.434 seconds (JVM running for 8.442)2020-05-22 22:49:42.196  INFO 2916 --- [169.254.218.126] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'2020-05-22 22:49:42.196  INFO 2916 --- [169.254.218.126] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'2020-05-22 22:49:42.208  INFO 2916 --- [169.254.218.126] o.s.web.servlet.DispatcherServlet        : Completed initialization in 12 ms

启动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=53594: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:50:44.779  INFO 12160 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$616b51b6] 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:50:45.697  INFO 12160 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:90602020-05-22 22:50:46.084  INFO 12160 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Located environment: name=config-consumer-001, profiles=[dev], label=null, version=null, state=null2020-05-22 22:50:46.085  INFO 12160 --- [           main] b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource {name='configService', propertySources=[MapPropertySource {name='config-consumer-001-dev'}]}2020-05-22 22:50:46.088  INFO 12160 --- [           main] .l.t.s.c.t.c.c.ConfigConsumerApplication : The following profiles are active: dev2020-05-22 22:50:46.786  INFO 12160 --- [           main] o.s.cloud.context.scope.GenericScope     : BeanFactory id=3d53c625-f39f-3206-ba2a-c3072e301c8a2020-05-22 22:50:46.810  INFO 12160 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$616b51b6] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)2020-05-22 22:50:47.021  INFO 12160 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 9090 (http)2020-05-22 22:50:47.038  INFO 12160 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]2020-05-22 22:50:47.039  INFO 12160 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.16]2020-05-22 22:50:47.044  INFO 12160 --- [           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:50:47.131  INFO 12160 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext2020-05-22 22:50:47.131  INFO 12160 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1033 ms2020-05-22 22:50:47.655  INFO 12160 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'2020-05-22 22:50:48.596  INFO 12160 --- [           main] o.s.b.a.e.web.EndpointLinksResolver      : Exposing 17 endpoint(s) beneath base path '/actuator'2020-05-22 22:50:48.758  INFO 12160 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 9090 (http) with context path ''2020-05-22 22:50:48.761  INFO 12160 --- [           main] .l.t.s.c.t.c.c.ConfigConsumerApplication : Started ConfigConsumerApplication in 7.442 seconds (JVM running for 8.887)2020-05-22 22:50:49.167  INFO 12160 --- [169.254.218.126] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'2020-05-22 22:50:49.175  INFO 12160 --- [169.254.218.126] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'2020-05-22 22:50:49.176  INFO 12160 --- [169.254.218.126] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:90602020-05-22 22:50:49.189  INFO 12160 --- [169.254.218.126] o.s.web.servlet.DispatcherServlet        : Completed initialization in 14 ms2020-05-22 22:50:49.265  INFO 12160 --- [169.254.218.126] c.c.c.ConfigServicePropertySourceLocator : Located environment: name=config-consumer-001, profiles=[dev], label=null, version=null, state=null

可以看到配置中心客户端读取到了配置,在9090端口启动。
访问:http://localhost:9090/config/consumer/test
在这里插入图片描述

这样基于mysql的配置中心搭建完成

转载地址:http://iyme.baihongyu.com/

你可能感兴趣的文章
Linux上TCP的几个内核参数调优
查看>>
解Bug之路-dubbo流量上线时的非平滑问题
查看>>
记一次讲故事机器人的开发-我有故事,让机器人来读
查看>>
从Linux源码看Socket(TCP)的listen及连接队列
查看>>
高德网络定位算法的演进
查看>>
高德算法工程一体化实践和思考
查看>>
为亿级用户的美好出行而战!高德地图首届算法大赛落幕 95后北邮在读博士带队夺冠
查看>>
重温网络编程——常识(三)
查看>>
判断一个数是否是2的幂
查看>>
js 闭包(新)
查看>>
vscode 编辑python 如何格式化
查看>>
正则表达针对html(九)
查看>>
seo 回忆录百度基本概念(一)
查看>>
重新整理数据结构与算法(c#)—— 算法套路二分法[二十四]
查看>>
【golang-GUI开发】qt之signal和slot(一)
查看>>
kettle 执行 kjb 临时文件夹 /tmp permission denied 问题
查看>>
「从零单排HBase 06」你必须知道的HBase最佳实践
查看>>
「从零单排canal 04」 启动模块deployer源码解析
查看>>
用ThreadLocal来优化下代码吧
查看>>
netcore中使用session
查看>>