gpt4 book ai didi

aem - 如何使用 resourceResolver 在 java 中获取运行模式

转载 作者:行者123 更新时间:2023-12-02 06:52:36 36 4
gpt4 key购买 nike

我有一个只需要在发布实例中运行的 OSGi 服务。当我只有 resourceResolver 而没有 request 时,如何在 java 中获取运行模式?

最佳答案

要获取当前 AEM 实例正在使用的运行模式列表,您可以在您的服务和/或 servlet 中使用 SlingSettingService

import org.apache.felix.scr.annotations.Component;
import org.apache.sling.settings.SlingSettingsService;

@Component
public class MyService {

@Reference
private SlingSettingsService slingSettingsService;

private boolean isPublish() {
return this.slingSettingsService.getRunModes().contains("publish");
}
}

参见:

AEM 6.1:https://docs.adobe.com/docs/en/aem/6-1/ref/javadoc/org/apache/sling/settings/SlingSettingsService.html

AEM 6.2:https://docs.adobe.com/docs/en/aem/6-2/develop/ref/javadoc/org/apache/sling/settings/SlingSettingsService.html

AEM 6.3:https://helpx.adobe.com/experience-manager/6-3/sites/developing/using/reference-materials/javadoc/org/apache/sling/settings/SlingSettingsService.html

AEM 6.4:https://helpx.adobe.com/experience-manager/6-4/sites/developing/using/reference-materials/javadoc/org/apache/sling/settings/SlingSettingsService.html

关于aem - 如何使用 resourceResolver 在 java 中获取运行模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39665091/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com