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

本文共 3716 字,大约阅读时间需要 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-server
server:
port: 9060

4. ??????

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

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;
@SpringBootApplication
@EnableConfigServer
public 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: dev
management:
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")
@RefreshScope
public 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实现backtracking Jump Game回溯跳跃游戏算法(附完整源码)
查看>>
Objective-C实现BACKTRACKING 方法查找集合的幂集算法(附完整源码)
查看>>
Objective-C实现bailey borwein plouffe算法(附完整源码)
查看>>
Objective-C实现balanced parentheses平衡括号表达式算法(附完整源码)
查看>>
Objective-C实现base64加密和base64解密算法(附完整源码)
查看>>
Objective-C实现base64加解密(附完整源码)
查看>>
Objective-C实现base64编码 (附完整源码)
查看>>
Objective-C实现base85 编码算法(附完整源码)
查看>>
Objective-C实现basic graphs基本图算法(附完整源码)
查看>>
Objective-C实现BCC校验计算(附完整源码)
查看>>
Objective-C实现bead sort珠排序算法(附完整源码)
查看>>
Objective-C实现BeadSort珠排序算法(附完整源码)
查看>>
Objective-C实现bellman ford贝尔曼福特算法(附完整源码)
查看>>
Objective-C实现bellman-ford贝尔曼-福特算法(附完整源码)
查看>>
Objective-C实现bellman-ford贝尔曼-福特算法(附完整源码)
查看>>
Objective-C实现BellmanFord贝尔曼-福特算法(附完整源码)
查看>>
Objective-C实现bezier curve贝塞尔曲线算法(附完整源码)
查看>>
Objective-C实现bfs 最短路径算法(附完整源码)
查看>>
Objective-C实现BF算法 (附完整源码)
查看>>
Objective-C实现Bilateral Filter双边滤波器算法(附完整源码)
查看>>