如何使用resourceResolver在java中获取runmode

时间:2016-09-23 16:02:31

标签: cq5 aem aem-6

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

1 个答案:

答案 0 :(得分:5)

要获取当前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