我是靠谱客的博主 朴素嚓茶,最近开发中收集的这篇文章主要介绍spring cloud config入门,spring cloud config mysql数据库配置配置中心,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

之前进行了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-mysql

server:
  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
@EnableConfigServer
public 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.yml
spring:
  application:
    name: config-consumer-001
  cloud:
    config:
      uri: http://localhost:9060
      fail-fast: true
  profiles:
    active: dev
management:
  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")
@RefreshScope
public 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")
@RefreshScope
public class ConsumerController {

    @Value("${hello}")
    private String hello;

    @RequestMapping("/test")
    public String testConfig(){
        return String.format("hello is %s ",hello);
    }

}

启动 config-server-mysql:

"D:develop tooljdk1.8.0_151binjava.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 toolideaIU-2019.3.4.winlibidea_rt.jar=53536:D:develop toolideaIU-2019.3.4.winbin" -Dfile.encoding=UTF-8 -classpath "D:develop tooljdk1.8.0_151jrelibcharsets.jar;D:develop tooljdk1.8.0_151jrelibdeploy.jar;D:develop tooljdk1.8.0_151jrelibextaccess-bridge-64.jar;D:develop tooljdk1.8.0_151jrelibextcldrdata.jar;D:develop tooljdk1.8.0_151jrelibextdnsns.jar;D:develop tooljdk1.8.0_151jrelibextjaccess.jar;D:develop tooljdk1.8.0_151jrelibextjfxrt.jar;D:develop tooljdk1.8.0_151jrelibextlocaledata.jar;D:develop tooljdk1.8.0_151jrelibextnashorn.jar;D:develop tooljdk1.8.0_151jrelibextsunec.jar;D:develop tooljdk1.8.0_151jrelibextsunjce_provider.jar;D:develop tooljdk1.8.0_151jrelibextsunmscapi.jar;D:develop tooljdk1.8.0_151jrelibextsunpkcs11.jar;D:develop tooljdk1.8.0_151jrelibextzipfs.jar;D:develop tooljdk1.8.0_151jrelibjavaws.jar;D:develop tooljdk1.8.0_151jrelibjce.jar;D:develop tooljdk1.8.0_151jrelibjfr.jar;D:develop tooljdk1.8.0_151jrelibjfxswt.jar;D:develop tooljdk1.8.0_151jrelibjsse.jar;D:develop tooljdk1.8.0_151jrelibmanagement-agent.jar;D:develop tooljdk1.8.0_151jrelibplugin.jar;D:develop tooljdk1.8.0_151jrelibresources.jar;D:develop tooljdk1.8.0_151jrelibrt.jar;D:datagithubleo-test-allspring-cloud-test-allspring-cloud-test-001config-server-mysqltargetclasses;C:UsersT470.m2repositoryorgspringframeworkbootspring-boot-starter-web2.1.3.RELEASEspring-boot-starter-web-2.1.3.RELEASE.jar;C:UsersT470.m2repositoryorgspringframeworkbootspring-boot-starter2.1.3.RELEASEspring-boot-starter-2.1.3.RELEASE.jar;C:UsersT470.m2repositoryorgspringframeworkbootspring-boot2.1.3.RELEASEspring-boot-2.1.3.RELEASE.jar;C:UsersT470.m2repositoryorgspringframeworkbootspring-boot-autoconfigure2.1.3.RELEASEspring-boot-autoconfigure-2.1.3.RELEASE.jar;C:UsersT470.m2repositoryorgspringframeworkbootspring-boot-starter-logging2.1.3.RELEASEspring-boot-starter-logging-2.1.3.RELEASE.jar;C:UsersT470.m2repositorychqoslogbacklogback-classic1.2.3logback-classic-1.2.3.jar;C:UsersT470.m2repositorychqoslogbacklogback-core1.2.3logback-core-1.2.3.jar;C:UsersT470.m2repositoryorgapachelogginglog4jlog4j-to-slf4j2.11.2log4j-to-slf4j-2.11.2.jar;C:UsersT470.m2repositoryorgapachelogginglog4jlog4j-api2.11.2log4j-api-2.11.2.jar;C:UsersT470.m2repositoryorgslf4jjul-to-slf4j1.7.25jul-to-slf4j-1.7.25.jar;C:UsersT470.m2repositoryjavaxannotationjavax.annotation-api1.3.2javax.annotation-api-1.3.2.jar;C:UsersT470.m2repositoryorgspringframeworkspring-core5.1.5.RELEASEspring-core-5.1.5.RELEASE.jar;C:UsersT470.m2repositoryorgspringframeworkspring-jcl5.1.5.RELEASEspring-jcl-5.1.5.RELEASE.jar;C:UsersT470.m2repositoryorgspringframeworkbootspring-boot-starter-json2.1.3.RELEASEspring-boot-starter-json-2.1.3.RELEASE.jar;C:UsersT470.m2repositorycomfasterxmljacksoncorejackson-databind2.9.8jackson-databind-2.9.8.jar;C:UsersT470.m2repositorycomfasterxmljacksoncorejackson-core2.9.8jackson-core-2.9.8.jar;C:UsersT470.m2repositorycomfasterxmljacksondatatypejackson-datatype-jdk82.9.8jackson-datatype-jdk8-2.9.8.jar;C:UsersT470.m2repositorycomfasterxmljacksondatatypejackson-datatype-jsr3102.9.8jackson-datatype-jsr310-2.9.8.jar;C:UsersT470.m2repositorycomfasterxmljacksonmodulejackson-module-parameter-names2.9.8jackson-module-parameter-names-2.9.8.jar;C:UsersT470.m2repositoryorgspringframeworkbootspring-boot-starter-tomcat2.1.3.RELEASEspring-boot-starter-tomcat-2.1.3.RELEASE.jar;C:UsersT470.m2repositoryorgapachetomcatembedtomcat-embed-core9.0.16tomcat-embed-core-9.0.16.jar;C:UsersT470.m2repositoryorgapachetomcatembedtomcat-embed-el9.0.16tomcat-embed-el-9.0.16.jar;C:UsersT470.m2repositoryorgapachetomcatembedtomcat-embed-websocket9.0.16tomcat-embed-websocket-9.0.16.jar;C:UsersT470.m2repositoryorghibernatevalidatorhibernate-validator6.0.14.Finalhibernate-validator-6.0.14.Final.jar;C:UsersT470.m2repositoryjavaxvalidationvalidation-api2.0.1.Finalvalidation-api-2.0.1.Final.jar;C:UsersT470.m2repositoryorgjbossloggingjboss-logging3.3.2.Finaljboss-logging-3.3.2.Final.jar;C:UsersT470.m2repositorycomfasterxmlclassmate1.4.0classmate-1.4.0.jar;C:UsersT470.m2repositoryorgspringframeworkspring-web5.1.5.RELEASEspring-web-5.1.5.RELEASE.jar;C:UsersT470.m2repositoryorgspringframeworkspring-beans5.1.5.RELEASEspring-beans-5.1.5.RELEASE.jar;C:UsersT470.m2repositoryorgspringframeworkspring-webmvc5.1.5.RELEASEspring-webmvc-5.1.5.RELEASE.jar;C:UsersT470.m2repositoryorgspringframeworkspring-aop5.1.5.RELEASEspring-aop-5.1.5.RELEASE.jar;C:UsersT470.m2repositoryorgspringframeworkspring-context5.1.5.RELEASEspring-context-5.1.5.RELEASE.jar;C:UsersT470.m2repositoryorgspringframeworkspring-expression5.1.5.RELEASEspring-expression-5.1.5.RELEASE.jar;C:UsersT470.m2repositoryorgspringframeworkcloudspring-cloud-config-server2.1.3.RELEASEspring-cloud-config-server-2.1.3.RELEASE.jar;C:UsersT470.m2repositoryorgspringframeworkcloudspring-cloud-config-client2.1.3.RELEASEspring-cloud-config-client-2.1.3.RELEASE.jar;C:UsersT470.m2repositoryorgspringframeworkcloudspring-cloud-commons2.1.2.RELEASEspring-cloud-commons-2.1.2.RELEASE.jar;C:UsersT470.m2repositoryorgspringframeworkcloudspring-cloud-context2.1.2.RELEASEspring-cloud-context-2.1.2.RELEASE.jar;C:UsersT470.m2repositorycomfasterxmljacksoncorejackson-annotations2.9.0jackson-annotations-2.9.0.jar;C:UsersT470.m2repositoryorgspringframeworkbootspring-boot-starter-actuator2.1.3.RELEASEspring-boot-starter-actuator-2.1.3.RELEASE.jar;C:UsersT470.m2repositoryorgspringframeworkbootspring-boot-actuator-autoconfigure2.1.3.RELEASEspring-boot-actuator-autoconfigure-2.1.3.RELEASE.jar;C:UsersT470.m2repositoryorgspringframeworkbootspring-boot-actuator2.1.3.RELEASEspring-boot-actuator-2.1.3.RELEASE.jar;C:UsersT470.m2repositoryiomicrometermicrometer-core1.1.3micrometer-core-1.1.3.jar;C:UsersT470.m2repositoryorghdrhistogramHdrHistogram2.1.9HdrHistogram-2.1.9.jar;C:UsersT470.m2repositoryorglatencyutilsLatencyUtils2.0.3LatencyUtils-2.0.3.jar;C:UsersT470.m2repositoryorgspringframeworksecurityspring-security-crypto5.1.4.RELEASEspring-security-crypto-5.1.4.RELEASE.jar;C:UsersT470.m2repositoryorgspringframeworksecurityspring-security-rsa1.0.7.RELEASEspring-security-rsa-1.0.7.RELEASE.jar;C:UsersT470.m2repositoryorgbouncycastlebcpkix-jdk15on1.60bcpkix-jdk15on-1.60.jar;C:UsersT470.m2repositoryorgbouncycastlebcprov-jdk15on1.60bcprov-jdk15on-1.60.jar;C:UsersT470.m2repositoryorgeclipsejgitorg.eclipse.jgit5.1.3.201810200350-rorg.eclipse.jgit-5.1.3.201810200350-r.jar;C:UsersT470.m2repositorycomjcraftjsch.1.54jsch-0.1.54.jar;C:UsersT470.m2repositorycomjcraftjzlib1.1.1jzlib-1.1.1.jar;C:UsersT470.m2repositorycomgooglecodejavaewahJavaEWAH1.1.6JavaEWAH-1.1.6.jar;C:UsersT470.m2repositoryorgslf4jslf4j-api1.7.25slf4j-api-1.7.25.jar;C:UsersT470.m2repositoryorgeclipsejgitorg.eclipse.jgit.http.apache5.1.3.201810200350-rorg.eclipse.jgit.http.apache-5.1.3.201810200350-r.jar;C:UsersT470.m2repositoryorgapachehttpcomponentshttpclient4.5.7httpclient-4.5.7.jar;C:UsersT470.m2repositorycommons-codeccommons-codec1.11commons-codec-1.11.jar;C:UsersT470.m2repositoryorgapachehttpcomponentshttpcore4.4.11httpcore-4.4.11.jar;C:UsersT470.m2repositoryorgyamlsnakeyaml1.23snakeyaml-1.23.jar;C:UsersT470.m2repositorymysqlmysql-connector-java5.1.21mysql-connector-java-5.1.21.jar;C:UsersT470.m2repositoryorgspringframeworkbootspring-boot-starter-jdbc2.1.3.RELEASEspring-boot-starter-jdbc-2.1.3.RELEASE.jar;C:UsersT470.m2repositorycomzaxxerHikariCP3.2.0HikariCP-3.2.0.jar;C:UsersT470.m2repositoryorgspringframeworkspring-jdbc5.1.5.RELEASEspring-jdbc-5.1.5.RELEASE.jar;C:UsersT470.m2repositoryorgspringframeworkspring-tx5.1.5.RELEASEspring-tx-5.1.5.RELEASE.jar;C:UsersT470.m2repositoryorgspringframeworkbootspring-boot-starter-data-jpa2.1.3.RELEASEspring-boot-starter-data-jpa-2.1.3.RELEASE.jar;C:UsersT470.m2repositoryorgspringframeworkbootspring-boot-starter-aop2.1.3.RELEASEspring-boot-starter-aop-2.1.3.RELEASE.jar;C:UsersT470.m2repositoryorgaspectjaspectjweaver1.9.2aspectjweaver-1.9.2.jar;C:UsersT470.m2repositoryjavaxtransactionjavax.transaction-api1.3javax.transaction-api-1.3.jar;C:UsersT470.m2repositoryjavaxxmlbindjaxb-api2.3.1jaxb-api-2.3.1.jar;C:UsersT470.m2repositoryjavaxactivationjavax.activation-api1.2.0javax.activation-api-1.2.0.jar;C:UsersT470.m2repositoryorghibernatehibernate-core5.3.7.Finalhibernate-core-5.3.7.Final.jar;C:UsersT470.m2repositoryjavaxpersistencejavax.persistence-api2.2javax.persistence-api-2.2.jar;C:UsersT470.m2repositoryorgjavassistjavassist3.23.1-GAjavassist-3.23.1-GA.jar;C:UsersT470.m2repositorynetbytebuddybyte-buddy1.9.10byte-buddy-1.9.10.jar;C:UsersT470.m2repositoryantlrantlr2.7.7antlr-2.7.7.jar;C:UsersT470.m2repositoryorgjbossjandex2.0.5.Finaljandex-2.0.5.Final.jar;C:UsersT470.m2repositoryorgdom4jdom4j2.1.1dom4j-2.1.1.jar;C:UsersT470.m2repositoryorghibernatecommonhibernate-commons-annotations5.0.4.Finalhibernate-commons-annotations-5.0.4.Final.jar;C:UsersT470.m2repositoryorgspringframeworkdataspring-data-jpa2.1.5.RELEASEspring-data-jpa-2.1.5.RELEASE.jar;C:UsersT470.m2repositoryorgspringframeworkdataspring-data-commons2.1.5.RELEASEspring-data-commons-2.1.5.RELEASE.jar;C:UsersT470.m2repositoryorgspringframeworkspring-orm5.1.5.RELEASEspring-orm-5.1.5.RELEASE.jar;C:UsersT470.m2repositoryorgspringframeworkspring-aspects5.1.5.RELEASEspring-aspects-5.1.5.RELEASE.jar" com.leo.test.spring.cloud.test.config.server.mysql.ConfigServerMysqlApplication
2020-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: jdbc
2020-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-bf2bf9be1057
2020-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 tooljdk1.8.0_151bin;C:WindowsSunJavabin;C:Windowssystem32;C:Windows;D:develop toolpython36Scripts;D:develop toolpython36;D:develop toolscala-2.12.8bin;C:Program FilesInteliCLS Client;D:toolscala-2.10.4bin;D:develop toolhadoop-2.6.5bin;D:develop toolgradle-5.5.1bin;D:develop toolprotoc-3.6.1-win32bin;C:nwrfcsdklib;C:nwrfcsdkinclude;C:Program FilesIBMclidriverbin;D:toolmingw64bin;D:develop toolGOPATHbin;D:develop toolGOROOTgo-1.11bin;D:develop toolmysql-5.6.41-winx64bin;D:develop toolapache-maven-3.5.4/bin;C:Program Files (x86)Common FilesNetSarang;C:Windowssystem32;C:Windows;C:WindowsSystem32Wbem;C:WindowsSystem32WindowsPowerShellv1.0;C:Program FilesIntelWiFibin;C:Program FilesCommon FilesIntelWirelessCommon;C:Program FilesOpenVPNbin;D:develop tooljdk1.8.0_151/bin;C:Program FilesGitcmd;C:Program FilesMicrosoft SQL Server110ToolsBinn;C:Program Filesdotnet;D:Program FilesTortoiseSVNbin;C:Program Files (x86)IntelIntel(R) Management Engine ComponentsDAL;C:Program FilesIntelIntel(R) Management Engine ComponentsDAL;C:Program Files (x86)Common FilesThunder NetworkKanKanCodecs;C:Program FilesMicrosoft SQL Server120ToolsBinn;C:Program FilesMicrosoft SQL Server130ToolsBinn;D:develop toolapache-ant-1.9.14bin;C:Program FilesIntelWiFibin;C:Program FilesCommon FilesIntelWirelessCommon;C:UsersT470AppDataLocalProgramsFiddler;.]
2020-05-22 22:49:38.773  INFO 2916 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2020-05-22 22:49:38.773  INFO 2916 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1381 ms
2020-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 found
2020-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.MySQL5Dialect
2020-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 warning
2020-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 tooljdk1.8.0_151binjava.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 toolideaIU-2019.3.4.winlibidea_rt.jar=53594:D:develop toolideaIU-2019.3.4.winbin" -Dfile.encoding=UTF-8 -classpath "D:develop tooljdk1.8.0_151jrelibcharsets.jar;D:develop tooljdk1.8.0_151jrelibdeploy.jar;D:develop tooljdk1.8.0_151jrelibextaccess-bridge-64.jar;D:develop tooljdk1.8.0_151jrelibextcldrdata.jar;D:develop tooljdk1.8.0_151jrelibextdnsns.jar;D:develop tooljdk1.8.0_151jrelibextjaccess.jar;D:develop tooljdk1.8.0_151jrelibextjfxrt.jar;D:develop tooljdk1.8.0_151jrelibextlocaledata.jar;D:develop tooljdk1.8.0_151jrelibextnashorn.jar;D:develop tooljdk1.8.0_151jrelibextsunec.jar;D:develop tooljdk1.8.0_151jrelibextsunjce_provider.jar;D:develop tooljdk1.8.0_151jrelibextsunmscapi.jar;D:develop tooljdk1.8.0_151jrelibextsunpkcs11.jar;D:develop tooljdk1.8.0_151jrelibextzipfs.jar;D:develop tooljdk1.8.0_151jrelibjavaws.jar;D:develop tooljdk1.8.0_151jrelibjce.jar;D:develop tooljdk1.8.0_151jrelibjfr.jar;D:develop tooljdk1.8.0_151jrelibjfxswt.jar;D:develop tooljdk1.8.0_151jrelibjsse.jar;D:develop tooljdk1.8.0_151jrelibmanagement-agent.jar;D:develop tooljdk1.8.0_151jrelibplugin.jar;D:develop tooljdk1.8.0_151jrelibresources.jar;D:develop tooljdk1.8.0_151jrelibrt.jar;D:datagithubleo-test-allspring-cloud-test-allspring-cloud-test-001config-consumer-001targetclasses;C:UsersT470.m2repositoryorgspringframeworkbootspring-boot-starter-web2.1.3.RELEASEspring-boot-starter-web-2.1.3.RELEASE.jar;C:UsersT470.m2repositoryorgspringframeworkbootspring-boot-starter2.1.3.RELEASEspring-boot-starter-2.1.3.RELEASE.jar;C:UsersT470.m2repositoryorgspringframeworkbootspring-boot2.1.3.RELEASEspring-boot-2.1.3.RELEASE.jar;C:UsersT470.m2repositoryorgspringframeworkbootspring-boot-autoconfigure2.1.3.RELEASEspring-boot-autoconfigure-2.1.3.RELEASE.jar;C:UsersT470.m2repositoryorgspringframeworkbootspring-boot-starter-logging2.1.3.RELEASEspring-boot-starter-logging-2.1.3.RELEASE.jar;C:UsersT470.m2repositorychqoslogbacklogback-classic1.2.3logback-classic-1.2.3.jar;C:UsersT470.m2repositorychqoslogbacklogback-core1.2.3logback-core-1.2.3.jar;C:UsersT470.m2repositoryorgslf4jslf4j-api1.7.25slf4j-api-1.7.25.jar;C:UsersT470.m2repositoryorgapachelogginglog4jlog4j-to-slf4j2.11.2log4j-to-slf4j-2.11.2.jar;C:UsersT470.m2repositoryorgapachelogginglog4jlog4j-api2.11.2log4j-api-2.11.2.jar;C:UsersT470.m2repositoryorgslf4jjul-to-slf4j1.7.25jul-to-slf4j-1.7.25.jar;C:UsersT470.m2repositoryjavaxannotationjavax.annotation-api1.3.2javax.annotation-api-1.3.2.jar;C:UsersT470.m2repositoryorgspringframeworkspring-core5.1.5.RELEASEspring-core-5.1.5.RELEASE.jar;C:UsersT470.m2repositoryorgspringframeworkspring-jcl5.1.5.RELEASEspring-jcl-5.1.5.RELEASE.jar;C:UsersT470.m2repositoryorgyamlsnakeyaml1.23snakeyaml-1.23.jar;C:UsersT470.m2repositoryorgspringframeworkbootspring-boot-starter-json2.1.3.RELEASEspring-boot-starter-json-2.1.3.RELEASE.jar;C:UsersT470.m2repositorycomfasterxmljacksondatatypejackson-datatype-jdk82.9.8jackson-datatype-jdk8-2.9.8.jar;C:UsersT470.m2repositorycomfasterxmljacksondatatypejackson-datatype-jsr3102.9.8jackson-datatype-jsr310-2.9.8.jar;C:UsersT470.m2repositorycomfasterxmljacksonmodulejackson-module-parameter-names2.9.8jackson-module-parameter-names-2.9.8.jar;C:UsersT470.m2repositoryorgspringframeworkbootspring-boot-starter-tomcat2.1.3.RELEASEspring-boot-starter-tomcat-2.1.3.RELEASE.jar;C:UsersT470.m2repositoryorgapachetomcatembedtomcat-embed-core9.0.16tomcat-embed-core-9.0.16.jar;C:UsersT470.m2repositoryorgapachetomcatembedtomcat-embed-el9.0.16tomcat-embed-el-9.0.16.jar;C:UsersT470.m2repositoryorgapachetomcatembedtomcat-embed-websocket9.0.16tomcat-embed-websocket-9.0.16.jar;C:UsersT470.m2repositoryorghibernatevalidatorhibernate-validator6.0.14.Finalhibernate-validator-6.0.14.Final.jar;C:UsersT470.m2repositoryjavaxvalidationvalidation-api2.0.1.Finalvalidation-api-2.0.1.Final.jar;C:UsersT470.m2repositoryorgjbossloggingjboss-logging3.3.2.Finaljboss-logging-3.3.2.Final.jar;C:UsersT470.m2repositorycomfasterxmlclassmate1.4.0classmate-1.4.0.jar;C:UsersT470.m2repositoryorgspringframeworkspring-web5.1.5.RELEASEspring-web-5.1.5.RELEASE.jar;C:UsersT470.m2repositoryorgspringframeworkspring-beans5.1.5.RELEASEspring-beans-5.1.5.RELEASE.jar;C:UsersT470.m2repositoryorgspringframeworkspring-webmvc5.1.5.RELEASEspring-webmvc-5.1.5.RELEASE.jar;C:UsersT470.m2repositoryorgspringframeworkspring-aop5.1.5.RELEASEspring-aop-5.1.5.RELEASE.jar;C:UsersT470.m2repositoryorgspringframeworkspring-context5.1.5.RELEASEspring-context-5.1.5.RELEASE.jar;C:UsersT470.m2repositoryorgspringframeworkspring-expression5.1.5.RELEASEspring-expression-5.1.5.RELEASE.jar;C:UsersT470.m2repositoryorgspringframeworkcloudspring-cloud-starter-config2.1.3.RELEASEspring-cloud-starter-config-2.1.3.RELEASE.jar;C:UsersT470.m2repositoryorgspringframeworkcloudspring-cloud-starter2.1.2.RELEASEspring-cloud-starter-2.1.2.RELEASE.jar;C:UsersT470.m2repositoryorgspringframeworkcloudspring-cloud-context2.1.2.RELEASEspring-cloud-context-2.1.2.RELEASE.jar;C:UsersT470.m2repositoryorgspringframeworksecurityspring-security-crypto5.1.4.RELEASEspring-security-crypto-5.1.4.RELEASE.jar;C:UsersT470.m2repositoryorgspringframeworkcloudspring-cloud-commons2.1.2.RELEASEspring-cloud-commons-2.1.2.RELEASE.jar;C:UsersT470.m2repositoryorgspringframeworksecurityspring-security-rsa1.0.7.RELEASEspring-security-rsa-1.0.7.RELEASE.jar;C:UsersT470.m2repositoryorgbouncycastlebcpkix-jdk15on1.60bcpkix-jdk15on-1.60.jar;C:UsersT470.m2repositoryorgbouncycastlebcprov-jdk15on1.60bcprov-jdk15on-1.60.jar;C:UsersT470.m2repositoryorgspringframeworkcloudspring-cloud-config-client2.1.3.RELEASEspring-cloud-config-client-2.1.3.RELEASE.jar;C:UsersT470.m2repositorycomfasterxmljacksoncorejackson-annotations2.9.0jackson-annotations-2.9.0.jar;C:UsersT470.m2repositorycomfasterxmljacksoncorejackson-databind2.9.8jackson-databind-2.9.8.jar;C:UsersT470.m2repositorycomfasterxmljacksoncorejackson-core2.9.8jackson-core-2.9.8.jar;C:UsersT470.m2repositoryorgspringframeworkbootspring-boot-starter-actuator2.1.3.RELEASEspring-boot-starter-actuator-2.1.3.RELEASE.jar;C:UsersT470.m2repositoryorgspringframeworkbootspring-boot-actuator-autoconfigure2.1.3.RELEASEspring-boot-actuator-autoconfigure-2.1.3.RELEASE.jar;C:UsersT470.m2repositoryorgspringframeworkbootspring-boot-actuator2.1.3.RELEASEspring-boot-actuator-2.1.3.RELEASE.jar;C:UsersT470.m2repositoryiomicrometermicrometer-core1.1.3micrometer-core-1.1.3.jar;C:UsersT470.m2repositoryorghdrhistogramHdrHistogram2.1.9HdrHistogram-2.1.9.jar;C:UsersT470.m2repositoryorglatencyutilsLatencyUtils2.0.3LatencyUtils-2.0.3.jar" com.leo.test.spring.cloud.test.config.consumer.ConfigConsumerApplication
2020-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:9060
2020-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=null
2020-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: dev
2020-05-22 22:50:46.786  INFO 12160 --- [           main] o.s.cloud.context.scope.GenericScope     : BeanFactory id=3d53c625-f39f-3206-ba2a-c3072e301c8a
2020-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 tooljdk1.8.0_151bin;C:WindowsSunJavabin;C:Windowssystem32;C:Windows;D:develop toolpython36Scripts;D:develop toolpython36;D:develop toolscala-2.12.8bin;C:Program FilesInteliCLS Client;D:toolscala-2.10.4bin;D:develop toolhadoop-2.6.5bin;D:develop toolgradle-5.5.1bin;D:develop toolprotoc-3.6.1-win32bin;C:nwrfcsdklib;C:nwrfcsdkinclude;C:Program FilesIBMclidriverbin;D:toolmingw64bin;D:develop toolGOPATHbin;D:develop toolGOROOTgo-1.11bin;D:develop toolmysql-5.6.41-winx64bin;D:develop toolapache-maven-3.5.4/bin;C:Program Files (x86)Common FilesNetSarang;C:Windowssystem32;C:Windows;C:WindowsSystem32Wbem;C:WindowsSystem32WindowsPowerShellv1.0;C:Program FilesIntelWiFibin;C:Program FilesCommon FilesIntelWirelessCommon;C:Program FilesOpenVPNbin;D:develop tooljdk1.8.0_151/bin;C:Program FilesGitcmd;C:Program FilesMicrosoft SQL Server110ToolsBinn;C:Program Filesdotnet;D:Program FilesTortoiseSVNbin;C:Program Files (x86)IntelIntel(R) Management Engine ComponentsDAL;C:Program FilesIntelIntel(R) Management Engine ComponentsDAL;C:Program Files (x86)Common FilesThunder NetworkKanKanCodecs;C:Program FilesMicrosoft SQL Server120ToolsBinn;C:Program FilesMicrosoft SQL Server130ToolsBinn;D:develop toolapache-ant-1.9.14bin;C:Program FilesIntelWiFibin;C:Program FilesCommon FilesIntelWirelessCommon;C:UsersT470AppDataLocalProgramsFiddler;.]
2020-05-22 22:50:47.131  INFO 12160 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2020-05-22 22:50:47.131  INFO 12160 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1033 ms
2020-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:9060
2020-05-22 22:50:49.189  INFO 12160 --- [169.254.218.126] o.s.web.servlet.DispatcherServlet        : Completed initialization in 14 ms
2020-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的配置中心搭建完成

最后

以上就是朴素嚓茶为你收集整理的spring cloud config入门,spring cloud config mysql数据库配置配置中心的全部内容,希望文章能够帮你解决spring cloud config入门,spring cloud config mysql数据库配置配置中心所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(66)

评论列表共有 0 条评论

立即
投稿
返回
顶部