mysql jdbc config_springcloud config+jdbc(mysql)来实现配置管理

1.spring cloud config支持多种形式的统一配置管理,如git,subversion,jdbc,vault等多种形式的配置管理,接下来我们来说说mysql+springcloud config来实现统一配置管理。

2.首先是config server

buildscript {

ext {

springBootVersion = '2.0.0.RELEASE'

}

repositories {

mavenCentral()

maven { url "https://repo.spring.io/milestone" }

}

dependencies {

classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")

}

}

apply plugin: 'java'

apply plugin: 'org.springframework.boot'

apply plugin: 'io.spring.dependency-management'

group = 'com.gholly.spring.cofig.db.server'

version = '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {

mavenCentral()

maven { url "https://repo.spring.io/milestone" }

}

ext {

springCloudVersion = 'Finchley.M7'

}

dependencies {

compile('org.springframework.boot:spring-boot-starter-web')

compile('org.springframework.boot:spring-boot-starter-actuator')

compile('org.springframework.cloud:spring-cloud-starter-config')

compile('org.springframework.cloud:spring-cloud-config-server')

compile('mysql:mysql-connector-java')

testCompile('org.springframework.boot:spring-boot-starter-test')

}

dependencyManagement {

imports {

mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"

}

}

application.yml

server:

port: 8888

spring:

profiles:

active: jdbc

application:

name: config-server

cloud:

config:

label: master

server:

jdbc:

sql: SELECT `KEY`, `VALUE` from PROPERTIES where APPLICATION=? and PROFILE=? and LABEL=?

order: 0

default-label: master

datasource:

url: jdbc:mysql://127.0.0.1:3306/test?useSSL=false

username: root

password: 123456

driver-class-name: com.mysql.jdbc.Driver

maxActive: 50

java文件:

package com.gholly.config.db.server;

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

import org.springframework.cloud.config.server.EnableConfigServer;

@SpringBootApplication

@EnableConfigServer

public class ConfigApplication {

public static void main(String[] args) {

SpringApplication.run(ConfigApplication.class,args);

}

}

mysql:

5b8aec5f34f1076ef9f7b013a87334b4.png

3.客户端

@RestController

@SpringBootApplication

public class ClientApplication {

public static void main(String[] args) {

SpringApplication.run(ClientApplication.class,args);

}

@Value("${a.b}")

public String hh;

@RequestMapping("/hh")

public String test(){

return hh;

}

}

application.yml

server:

port: 8008

spring:

cloud:

config:

uri: http://localhost:8888/

profile: default

label: master

bus:

enabled: true

application:

name: config #此名字需与mysql中的application相对应

验证:

979d7474b2a90ec8ac2b42b306a7b52f.png

example地址为:

https://github.com/gholly/spring-config-server-db

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值