サーバーの構成
URIのプレースホルダをGitは
前の例では、アドレスに対応する環境で構成spring.cloud.config.profile、プロファイルのspring.cloud.config.uri名によって設定アドレスspring.cloud.config.name構成センターのサーバー構成を構成し
server:
port: 8102
spring:
application:
name: config-client-1
cloud:
config:
label: master
uri: http://localhost:8101
# 此处配置了配置文件的名称
name: client-config
profile: dev
复制代码
パターンマッチングとリポジトリの複数
アプリケーション名とプロファイルでは、春のクラウドサーバーは、より複雑なコンフィギュレーション・モードをサポートしている、あなたは、カンマで区切られた名前を、一致するワイルドカード{アプリケーション} / {プロファイル}ルールを使用することができます。
例:
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
复制代码
検索パス
検索パスのプレースホルダ
spring:
cloud:
config:
server:
git:
uri: https://gitee.com/chendom/SpringCloudConfig.git
username: xx
password: xx
#配置搜索路径
search-paths: config,config*
复制代码
検索パス:設定、コンフィグ*は、設定パスを参照するパス接頭辞の検索ですべての設定ファイルに、configされていますか
spring:
cloud:
config:
server:
git:
uri: https://gitee.com/chendom/SpringCloudConfig.git
username: xx
password: xx
#配置搜索路径
search-paths: *{application}*
#表示合法的将远程仓库拷贝到本地
clone-on-start: true
复制代码
クローンオンスタート:真は、検索パスは* {アプリケーション} *、**必須、または使用「{アプリケーション}」に設定する必要があり、さまざまなアイテムを一致させるために、リポジトリの法的コピーをローカルキャッシュにリモートであることを示します
例と春の雲とMySQL
ポンポン依存:
<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>
复制代码
プロファイル
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
复制代码
そして、クライアントは前の例と同じです
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;
}
}
复制代码
リクエストはlocalhostを:以下に示すように8104 /のgetValueは、得られた結果:
春の雲コンフィグスキルの使用に関連します
spring:
cloud:
config:
allowOverride:true
overrideNone: true
overrideSystemProperties: false
复制代码
-
AllowOverrideの:識別overrideSystemPropertiesプロパティが有効になっています。デフォルトでは、真であるfalseに設定されています
-
overrideNone:AllowOverrideのがtrueの場合、overrideNoneをtrueに設定し、優先度の低いの外観構成、およびソースのプロパティは、既存のデフォルトを上書きすることはできませんが偽であります
-
overrideSystemPropertiesは:昔のコンフィギュレーションは、洗浄性をカバーすることである識別し、デフォルトはtrueです。
ます。https://juejin.im/post/5ceb2da96fb9a07ee16905f8で再現