내 커뮤니티 업적 표시줄을 확대합니다.

Submissions are now open for the 2026 Adobe Experience Maker Awards.

Mark Solution

활동이 없어 이 대화는 잠겼습니다. 새 게시물을 작성해 주세요.

해결됨

Detect instance runmode programmatically in AEM as cloud service

Avatar

Community Advisor

Hi All,

 

Is there any alternative to detect run-mode of instance in AEM as cloud service as slingSettingsService shows as deprecated?

 

The use case is to execute code only on author or publish instances but not both.

 

Thanks,

Ram

1 채택된 해결책 개

Avatar

정확한 답변 작성자:
Employee Advisor

Not sure if this blog article has been specifically been written for you But it adresses your question quite good:

 

https://blog.osoco.de/2021/07/the-truth-about-aem-run-modes/

 

 

원본 게시물의 솔루션 보기

3 답변 개

Avatar

Community Advisor

Hi @rampai 

 

The solution is still in planning phase and no API is exposed like SlingSettingService to get the run mode.

https://github.com/Adobe-Consulting-Services/acs-aem-commons/issues/2476

 

In the mean time you can create an OSGi service and set the run mode config value in OSGi configuration and read it in your code. That should resolve the issue.

Here is an article which will give a good idea:

https://cqdump.joerghoh.de/2018/09/12/referencing-runmodes-in-java/

 

Thanks!

Avatar

Community Advisor

Hello,

 

Please check https://medium.com/adobetech/custom-runmodes-on-aem-as-a-cloud-service-79b757f51a6b for custom runmodes (not to be used or used cautiously) which discusses about some good practices.

It seems to provide an example of refactored code.

From the reference above, we can try this

@Property(label = "Environment Type",
        description = "Should be dev/stage/prod/local - default is local")
private static final String ENVIRONMENT_TYPE = "environment.type";
private String environmentType;

@Activate
@Modified
protected void activate(final Map<String, String> config) {
    environmentType = PropertiesUtil.toString(config.get(ENVIRONMENT_TYPE), DEFAULT_ENVIRONMENT_TYPE);
    log.debug("Environment Type Service Activated with Environment Type of {}", environmentType);
}



public String getEnvironmentType() {
    return environmentType;
}

Avatar

정확한 답변 작성자:
Employee Advisor

Not sure if this blog article has been specifically been written for you But it adresses your question quite good:

 

https://blog.osoco.de/2021/07/the-truth-about-aem-run-modes/