博客
关于我
spring cloud config入门,spring cloud config mysql数据库配置配置中心
阅读量:346 次
发布时间: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/

你可能感兴趣的文章
POJ2728 Desert King
查看>>
POJ2794 Double Patience[离散概率 状压DP]
查看>>
poj2828(线段树查找序列第k小的值)
查看>>
POJ2891:Strange Way to Express Integers——题解
查看>>
poj3045 Cow Acrobats(二分最大化最小值)
查看>>
poj3061 Subsequence(尺取法)
查看>>
poj3074 DLX精确覆盖
查看>>
poj3252(组合数)
查看>>
Qt笔记——QToolBox开发简易QQ聊天界面
查看>>
poj3307
查看>>
Qt笔记——QString与隐式共享、MVC架构
查看>>
Qt笔记——QSemaphore处理生产者/消费者模式
查看>>
Qt笔记——QMutex&QWaitCondition处理生产者消费者模式
查看>>
Qt笔记——QLable+QPixmap图片缩放踩坑
查看>>
Qt笔记——foreach与forever
查看>>
QT程序怎么挪到Linux下,linux+Qt程序如何打包发布
查看>>
Qt知识:视图框架QGraphicsWidget详解
查看>>
SpringBoot中项目启动及定时任务缓存数据库常用数据至内存变量并转换后高频调用
查看>>
Qt知识: 画刷风格
查看>>
QT的OpenGL渲染窗QOpenGLWidget Class
查看>>