mysql配置文件没有spring_spring cloud config使用mysql存储配置文件
spring cloud config使用mysql存儲配置文件
1.結構圖
2.pom.xml:
4.0.0
com.didispace
config-server-db
1.0.0
jar
config-server-db
Spring Cloud In Action
org.springframework.boot
spring-boot-starter-parent
1.5.11.RELEASE
UTF-8
1.8
org.springframework.cloud
spring-cloud-config-server
org.springframework.boot
spring-boot-starter-jdbc
org.flywaydb
flyway-core
5.0.3
mysql
mysql-connector-java
5.1.21
org.springframework.boot
spring-boot-starter-test
test
org.springframework.cloud
spring-cloud-dependencies
Edgware.SR3
pom
import
org.springframework.boot
spring-boot-maven-plugin
3.application.properties:
spring.application.name=config-server-db
server.port=10020spring.profiles.active=jdbc
spring.cloud.config.server.jdbc.sql=SELECT `KEY`, `VALUE` from PROPERTIES where APPLICATION=? and PROFILE=? and LABEL=?spring.datasource.url=jdbc:mysql://localhost:3306/config-server-db
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
flyway.locations=/schema
4.V1_Base_version.sql:
CREATE TABLE `properties` (
`id`int(11) NOT NULL,
`key` varchar(50) NOT NULL,
`value` varchar(500) NOT NULL,
`application` varchar(50) NOT NULL,
`profile` varchar(50) NOT NULL,
`label` varchar(50) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
5.啟動項:
@EnableConfigServer
@SpringBootApplicationpublic classConfigServerBootstrap {public static voidmain(String[] args) {
ApplicationContext context= SpringApplication.run(ConfigServerBootstrap.class);
JdbcTemplate jdbcTemplate= context.getBean(JdbcTemplate.class);
jdbcTemplate.execute("delete from properties");
jdbcTemplate.execute("INSERT INTO properties VALUES(1, 'com.didispace.message', 'test-stage-master', 'config-client', 'stage', 'master')");
jdbcTemplate.execute("INSERT INTO properties VALUES(2, 'com.didispace.message', 'test-online-master', 'config-client', 'online', 'master')");
jdbcTemplate.execute("INSERT INTO properties VALUES(3, 'com.didispace.message', 'test-online-develop', 'config-client', 'online', 'develop')");
jdbcTemplate.execute("INSERT INTO properties VALUES(4, 'com.didispace.message', 'hello-online-master', 'hello-service', 'online', 'master')");
jdbcTemplate.execute("INSERT INTO properties VALUES(5, 'com.didispace.message', 'hello-online-develop', 'hello-service', 'online', 'develop')");
}
}
只需要建立一個
config-server-db數(shù)據(jù)庫就行,表不用自己創(chuàng)建,
flyway會自動幫你創(chuàng)建好數(shù)據(jù)庫表。直接運行項目就行,訪問方式和使用git獲取配置文件的方式一樣,返回的數(shù)據(jù)類型也是一樣的。
值得注意的是配置中心想要用mysql存儲配置文件,必須是
Edgware版本才行,
Dalston版本不行。
總結
以上是生活随笔為你收集整理的mysql配置文件没有spring_spring cloud config使用mysql存储配置文件的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 做一次b超多少钱啊?
- 下一篇: 带水的网名微信名字
