博客
关于我
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/

你可能感兴趣的文章
onCreate()方法中的参数Bundle savedInstanceState 的意义用法
查看>>
One good websit for c#
查看>>
One-Shot学习/一次学习(One-shot learning)
查看>>
OneASP 安全公开课,深圳站, Come Here, Feel Safe!
查看>>
OneBlog Shiro 反序列化漏洞复现
查看>>
oneM2M
查看>>
Oneplus5重装攻略
查看>>
one_day_one--mkdir
查看>>
ONI文件生成与读取
查看>>
Vue 项目中实现高效的消息提示与确认对话框功能(模版)
查看>>
Online PDF to PNG、JPEG、WEBP、 TXT - toolfk
查看>>
onlstm时间复杂度_CRF和LSTM 模型在序列标注上的优劣?
查看>>
onlyoffice新版5.1.2版解决中文汉字输入重复等问题
查看>>
onnx导出动态输入
查看>>
onnx导出动态输入
查看>>
onScrollStateChanged无效
查看>>
onTouchEvent构造器
查看>>
on_member_join 和删除不起作用.如何让它发挥作用?
查看>>
oobbs开发手记
查看>>
OOM怎么办,教你生成dump文件以及查看(IT枫斗者)
查看>>