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

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

Spring Cloud Config?MySQL??????

1. ?????

Spring Cloud Config?Spring Cloud????????????????????????????Git?????????????????????MySQL???????????????????MySQL????????

  • ????????????????????????
  • ?????????????????????????
  • ??????????????????

2. ????

2.1 ??MySQL

?????MySQL??????????????????MySQL???

mysql -u root -p

??MySQL root????????MySQL??????

2.2 ???????

??MySQL????????????

CREATE DATABASE config;USE config;CREATE TABLE config (    id INT PRIMARY KEY 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);

3. Spring Boot????

3.1 pom.xml??

????pom.xml?????????

org.springframework.boot
spring-boot-starter-web
org.springframework.cloud
spring-cloud-config-server
mysql
mysql-connector-java
5.1.21
org.springframework.boot
spring-boot-starter-jdbc
org.springframework.boot
spring-boot-starter-data-jpa

3.2 ????

??application.properties??bootstrap.properties?????????

spring:    datasource:        url: jdbc:mysql://localhost:3306/config        username: root        password: root        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-serverserver:    port: 9060

4. ??????

????????????

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

?????

mvn spring-boot:run

????????????http://localhost:9060?

5. ???????

5.1 pom.xml??

??????pom.xml?

org.springframework.boot
spring-boot-starter-web
org.springframework.cloud
spring-cloud-starter-config

5.2 ????

??bootstrap.yml???

spring:    application:        name: config-consumer    cloud:        config:            uri: http://localhost:9060            fail-fast: true    profiles:        active: devmanagement:    endpoints:        web:            exposure:                include: '*'

5.3 ?????

????????

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);    }}

?????

mvn spring-boot:run

6. ??

6.1 ??????

????????????????

http://localhost:9060/config/consumer/test

6.2 ???????

?MySQL??????????????

SELECT * FROM config WHERE application='config-server' AND profile='dev';

7. ??

??????????????????MySQL?Spring Cloud Config???????????????????????????????????????????????????????????????

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

你可能感兴趣的文章
Objective-C实现有限状态机(附完整源码)
查看>>
Objective-C实现有限状态自动机FSM(附完整源码)
查看>>
Objective-C实现有限集上给定关系的自反关系矩阵和对称闭包关系矩阵(附完整源码)
查看>>
Objective-C实现朴素贝叶斯算法(附完整源码)
查看>>
Objective-C实现杰卡德距离算法(附完整源码)
查看>>
Objective-C实现极值距离算法(附完整源码)
查看>>
Objective-C实现构造n以内的素数表(附完整源码)
查看>>
Objective-C实现某文件夹下文件重命名(附完整源码)
查看>>
Objective-C实现查找second Largest Element第二大元素算法(附完整源码)
查看>>
Objective-C实现查找整数数组中给定的最小数字算法(附完整源码)
查看>>
Objective-C实现根据cpu和磁盘序列号生成注册码( 附完整源码)
查看>>
Objective-C实现格雷码序列算法(附完整源码)
查看>>
Objective-C实现桥接模式(附完整源码)
查看>>
Objective-C实现检查一个数字是否可以被另一个数字整除算法(附完整源码)
查看>>
Objective-C实现检查三个点在 3D 中是否共线算法(附完整源码)
查看>>
Objective-C实现检查字符是否为字母算法(附完整源码)
查看>>
Objective-C实现检查给定图中是否存在循环算法(附完整源码)
查看>>
Objective-C实现检查给定字符串是否在camelCase中算法(附完整源码)
查看>>
Objective-C实现检查给定的字符串是否在kebabcase中算法(附完整源码)
查看>>
Objective-C实现欧几里得距离(附完整源码)
查看>>