3.2. Eclipse MicroProfile Config 設定

3.2.1. ConfigSource 管理リソースでのプロパティーの追加

プロパティーは管理リソースとして config-source サブシステムに直接保存できます。

手順

  • ConfigSource を作成し、プロパティーを追加します。

    /subsystem=microprofile-config-smallrye/config-source=props:add(properties={"name" = "jim"})

3.2.2. ディレクトリーを ConfigSources として設定

プロパティーがファイルとしてディレクトリーに保存されている場合、file-name はプロパティーの名前で、ファイルの内容はプロパティーの値になります。

手順

  1. ファイルを保存するディレクトリーを作成します。

    $ mkdir -p ~/config/prop-files/
  2. ディレクトリーに移動します。

    $ cd ~/config/prop-files/
  3. プロパティー name の値を保存するファイル name を作成します。

    $ touch name
  4. プロパティーの値をファイルに追加します。

    $ echo "jim" > name
  5. ファイル名がプロパティーであり、プロパティーの値が含まれるファイルが含まれる ConfigSource を作成します。

    /subsystem=microprofile-config-smallrye/config-source=file-props:add(dir={path=~/config/prop-files})

    これにより、以下の XML 設定が以下のようになります。

    <subsystem xmlns="urn:wildfly:microprofile-config-smallrye:1.0">
        <config-source name="file-props">
            <dir path="/etc/config/prop-files"/>
        </config-source>
    </subsystem>

3.2.3. ConfigSource クラスからの ConfigSource の取得

カスタムの org.eclipse.microprofile.config.spi.ConfigSource 実装クラスを作成および設定して、設定値のソースを提供することができます。

手順

  • 以下の管理 CLI コマンドは、org.example という名前の JBoss モジュールによって提供される、org.example.MyConfigSource という名前の実装クラスの ConfigSource を作成します。

    org.example モジュールから ConfigSource を使用する場合は、<module name="org.eclipse.microprofile.config.api"/> 依存関係を path/to/org/example/main/module.xml ファイルに追加します。

    /subsystem=microprofile-config-smallrye/config-source=my-config-source:add(class={name=org.example.MyConfigSource, module=org.example})

    このコマンドを実行すると、microprofile-config-smallrye サブシステムに以下の XML 設定が指定されます。

    <subsystem xmlns="urn:wildfly:microprofile-config-smallrye:1.0">
        <config-source name="my-config-source">
            <class name="org.example.MyConfigSource" module="org.example"/>
        </config-source>
    </subsystem>

カスタムの org.eclipse.microprofile.config.spi.ConfigSource 実装クラスによって提供されるプロパティーはすべての JBoss EAP デプロイメントで使用できます。

3.2.4. ConfigSourceProvider クラスからの ConfigSource 設定の取得

複数の ConfigSource インスタンスの実装を登録する、カスタムの org.eclipse.microprofile.config.spi.ConfigSourceProvider 実装クラスを作成および設定できます。

手順

  • config-source-provider を作成します。

    /subsystem=microprofile-config-smallrye/config-source-provider=my-config-source-provider:add(class={name=org.example.MyConfigSourceProvider, module=org.example})

    このコマンドは、org.example という名前の JBoss Module によって提供される、org.example.MyConfigSourceProvider という名前の実装クラスの config-source-provider を作成します。

    org.example モジュールから config-source-provider を使用する場合は、<module name="org.eclipse.microprofile.config.api"/> 依存関係を path/to/org/example/main/module.xml ファイルに追加します。

    このコマンドを実行すると、microprofile-config-smallrye サブシステムに以下の XML 設定が指定されます。

    <subsystem xmlns="urn:wildfly:microprofile-config-smallrye:1.0">
        <config-source-provider name="my-config-source-provider">
             <class name="org.example.MyConfigSourceProvider" module="org.example"/>
        </config-source-provider>
    </subsystem>

ConfigSourceProvider 実装によって提供されるプロパティーはすべての JBoss EAP デプロイメントで使用できます。

関連情報