3.2.3. 从 ConfigSource 类获取 ConfigSource
您可以创建和配置自定义 org.eclipse.microprofile.config.spi.ConfigSource 实施类,以提供配置值的来源。
流程
以下管理 CLI 命令为名为
org.example.MyConfig,该类由名为Source 的实施类创建一个 ConfigSourceorg.example的 JBoss 模块提供。如果要使用
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})/subsystem=microprofile-config-smallrye/config-source=my-config-source:add(class={name=org.example.MyConfigSource, module=org.example})Copy to Clipboard Copied! Toggle word wrap Toggle overflow 此命令将为
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><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>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
由自定义 org.eclipse.microprofile.config.spi.ConfigSource 实施类提供的属性可用于任何 JBoss EAP 部署。