【问题标题】:How to configure an OSGi service using descriptor file in Sling?如何使用 Sling 中的描述符文件配置 OSGi 服务?
【发布时间】:2026-01-07 06:05:01
【问题描述】:

我想使用文本文件配置 Apache Sling Service 用户映射器服务。我在jcr_root/apps/sling/config 下创建了一个文件,该文件名为 org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl.json。

这是文件的内容:

{
    "jcr:primaryType":"sling:OsgiConfig",
    "user.mapping" : "artifact.name=systemUserName"
}

文件已在 JCR 中创建并且属性已正确解析,但未配置服务。如何解决这个问题?

【问题讨论】:

    标签: osgi sling


    【解决方案1】:

    事实证明,要在 Sling 中配置服务,描述符文件必须存储在jcr_root/apps/sling/install 目录下。

    更多关于 Sling Installer 的信息可以在here找到。

    【讨论】:

    • 这是部分正确的。 Apache Sling JCR 安装程序是可配置的,请参阅:localhost:8080/system/console/configMgr/…。开箱即用,您可以将 OSGi 配置存储在 installconfig 中,其深度可达 4 级。标准做法是使用config 文件夹而不是install,例如/apps/<project name>/config。从那里,您可以进入运行模式规范,例如 config.prod.chicagoconfig.qa