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

How do I get runmode in java using resourceResolver

我有一个 OSGi 服务需要 运行 只在发布实例中。当我只有 resourceResolver 而没有请求时,如何在 java 中获得 运行mode?

要获取当前 AEM 实例正在使用的 运行 模式的列表,您可以在服务 and/or 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