Server configuration
Git the URI placeholder
In the previous example, we configured the configuration address spring.cloud.config.name configuration center server configuration through spring.cloud.config.uri the name of the profile, spring.cloud.config.profile configured with an address corresponding environment
server:
port: 8102
spring:
application:
name: config-client-1
cloud:
config:
label: master
uri: http://localhost:8101
# 此处配置了配置文件的名称
name: client-config
profile: dev
复制代码
Pattern matching and a plurality of repositories
On the application name and the profile, Spring Cloud Server also supports more complex configuration mode, you can use wildcards {application} / {profile} rule matching names, separated by commas.
example:
spring:
cloud:
config:
server:
git:
uri: https://gitee.com/chendom/SpringCloudConfig.git
username: xx
password: xx
#配置搜索路径
search-paths: config
repos:
simple: https://gitee.com/chendom/simple
special:
pattern: special*/dev*,*special*/dev*
uri: https://gitee.com/chendom/SpringCloudConfig-special
local:
pattern: local*
uri: /Users/chendom/test/SpringCloudConfig
复制代码
Search Path
Search path placeholder
spring:
cloud:
config:
server:
git:
uri: https://gitee.com/chendom/SpringCloudConfig.git
username: xx
password: xx
#配置搜索路径
search-paths: config,config*
复制代码
search-paths: config, config * refers to the config path is the path prefix search all configuration files are config or
spring:
cloud:
config:
server:
git:
uri: https://gitee.com/chendom/SpringCloudConfig.git
username: xx
password: xx
#配置搜索路径
search-paths: *{application}*
#表示合法的将远程仓库拷贝到本地
clone-on-start: true
复制代码
clone-on-start: true indicates legal copy of the repository is remote to the local cache, to match the different items, search-path needs to be configured to * {application} *, ** must, or use '{application}'
Spring Cloud and MySQL with examples
pom-dependent:
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.34</version>
</dependency>
</dependencies>
复制代码
Profiles
server:
port: 8103
spring:
cloud:
config:
server:
jdbc:
sql: SELECT `KEY`, `VALUE` FROM PROPERTIES WHERE application =? AND profile =? AND lable =?
label: master
refresh:
extra-refreshable: none
profiles:
#这里需要配置成是jdbc
active: jdbc
application:
name: config-server-db
## 数据配置
datasource:
url: jdbc:mysql://127.0.0.1:3306/config_db?useUnicode=true&characterEncoding=UTF-8
username: root
password: root@123
driver-class-name: com.mysql.jdbc.Driver
复制代码
And the client is still the same as the previous example
server:
port: 8104
spring:
application:
name: config-client-db
cloud:
config:
label: master
uri: http://localhost:8103
# 此处配置了配置文件的名称
name: client-config
profile: test
# 设置打印的日志级别
logging:
level:
root: debug
复制代码
@RestController
public class ConfigClientController {
@Value("${springcloud.configserver}")
public String value;
@RequestMapping("/getValue")
public String getValue(){
return value;
}
}
复制代码
Results 8104 / getValue obtained as shown below: Request localhost:
Spring Cloud Config related to the use of skills
spring:
cloud:
config:
allowOverride:true
overrideNone: true
overrideSystemProperties: false
复制代码
-
allowOverride: identification overrideSystemProperties property is enabled. The default is true, is set to false
-
overrideNone: When allowOverride is true, overrideNone set to true, the external configuration of a lower priority, and the properties of the source can not override any existing default is false
-
overrideSystemProperties: Identifies the old configuration is to cover the washing property, the default is true.
Reproduced in: https: //juejin.im/post/5ceb2da96fb9a07ee16905f8