Menu Close
12.4.4. カスタムのプロパティープレースホルダーリゾルバーの追加
カスタムのプレースホルダーリゾルバーを追加して、カスタムの暗号化などの特定の必要項目をサポートできます。また、PlaceholderResolver
サービスを使用して、Blueprint および ConfigAdmin がリゾルバーを使用できるようにすることもできます。
手順
以下の mvn 依存関係をプロジェクトの
pom.xml
に追加します。pom.xml
--- <dependency> <groupId>io.fabric8</groupId> <artifactId>fabric8-karaf-core</artifactId> </dependency> ---
PropertiesFunction インターフェースを実装し、CSR を使用して OSGi サービスとして登録します。
import io.fabric8.karaf.core.properties.function.PropertiesFunction; import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.ConfigurationPolicy; import org.apache.felix.scr.annotations.Service; @Component( immediate = true, policy = ConfigurationPolicy.IGNORE, createPid = false ) @Service(PropertiesFunction.class) public class MyPropertiesFunction implements PropertiesFunction { @Override public String getName() { return "myResolver"; } @Override public String apply(String remainder) { // Parse and resolve remainder return remainder; } }
以下のように、設定管理でリゾルバーを参照することができます。
properties
my.property = $[myResolver:value-to-resolve]