AEM 6:sling:osgiconfig 基于不同的环境

AEM 6: sling:osgiconfig based on different environments

我想为不同的环境创建 sling:osgiconfig。我知道文件夹必须遵循命名约定 config.<runmode/environment>.<author/publish>。我们有不同的环境,例如 https://test1-myapp.app.com or https://dev-myapp.app.com and so on. I logged into one of the environments in the publish mode to find out the runmode and all I could see was [crx3, nosamplecontent, publish, crx3tar]. This was the https://test1-myapp.app.com 发布环境。我不确定现在应该为我的配置文件夹取什么名字。

此外,一旦我准备就绪,我计划获取如下所示的属性:

SlingBindings bindings = (SlingBindings) slingRequest.getAttribute(SlingBindings.class.getName());
        SlingScriptHelper sling = bindings.getSling();
        Configuration conf = sling.getService(org.osgi.service.cm.ConfigurationAdmin.class).getConfiguration(pid);
        String[] myProp = (String[]) conf.getProperties().get("paths");

这是否适用于不同的环境,或者无论环境如何,它都会继续获取相同的 sling:osgiconfig 节点。

谢谢

这意味着您的服务器运行正在使用默认运行模式/安装运行模式,正如他们所说的那样。

publish 是因为它是一个发布实例,nosamplecontent 通常用于您不希望拥有安装示例内容。

这些是固定的 运行 模式,一旦与它们一起安装,之后便无法更改。

但是您可以通过 Sling 属性文件 sling.run.modes=dev,author 或通过在启动脚本中添加系统 属性 来定义自己的 运行 模式,例如开发或阶段 -Dsling.run.modes=stage,publish.关于此的更多信息可以是 found here.

使用默认的 运行 模式,很难为不同的实例提供不同的配置。您只能有 2 个配置,一个用于作者,另一个用于发布。

根据定义的 运行 模式获取配置,因此您的代码将在不同环境中适用的任何地方获取适当的配置。