コンフィギュレーション・センター・サーバーを作成します(春クラウドコンフィグ)

コンフィギュレーション・センター・サーバーを作成します。

altテキスト
altテキスト
altテキスト
altテキスト

プロジェクトを作成したプロファイルの内容を追加します。

server.port=9004
spring.application.name=spring-cloud-config-server-01
#git仓库地址
spring.cloud.config.server.git.uri=http://git.home/test/config-depot.git
#仓库内的相对路径
spring.cloud.config.server.git.search-paths=/config
#git用户名
spring.cloud.config.server.git.username=sunweisheng
#git密码
spring.cloud.config.server.git.password=********

物流センターを開くには、注釈を追加(SpringCloudConfigServerApplication.java)

@SpringBootApplication
//启动配置中心
@EnableConfigServer
public class SpringCloudConfigServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringCloudConfigServerApplication.class, args);
    }

}

Gitの倉庫でプロファイルを追加

Gitのリポジトリ名:CONFIG-デポー、configフォルダのルートの下に作成された倉庫、configディレクトリにプロファイルConfigDepot-Test.propertiesを作成し、設定ファイルの内容:bluersw.config = TEST-1
altテキスト
altテキスト

テスト構成センター

ブラウザ127.0.0.1:9004/ConfigDepot/Testでのアクセスは、コンフィギュレーション・ファイルJSON形式の内容を返し、証明はGitのリポジトリのコンテンツ流通センターの成功をお読みください。
altテキスト

{
    "name":"ConfigDepot",
    "profiles":["Test"],
    "label":null,
    "version":"e3fdd0937bba0ad2df3eefe09ac3ab33ca09397b",
    "state":null,
    "propertySources":[{
        "name":"http://git.home/test/config-depot.git/config/ConfigDepot-Test.properties",
        "source":{
            "bluersw.config":"Test-1"
        }
    }]
}

倉庫設定ファイルパスは、変換規則は、コンフィギュレーション・センターにアクセスするRESTインターフェースに変換することができます。

  • / {アプリケーション} / {プロファイル} / {ラベル}]
  • /{application}-{profile}.yml
  • /{label}/{application}-{profile}.yml
  • /{application}-{profile}.properties
  • /{label}/{application}-{profile}.properties

PS:設定ファイルの内容はテスト-3変更された場合、リポジトリ情報は、ページを更新し、キャッシュされていない、あなたが直接値(TEST-3)を見ることができるのGitを読むためのコンフィギュレーション・センターだけで変更されました。

ソース

Githubのリポジトリます。https://github.com/sunweisheng/spring-cloud-example

おすすめ

転載: www.cnblogs.com/bluersw/p/11610717.html