Skip to main content
Level 2
6月 3, 2022 6:42 上午 UTC
已解决

How to add run mode to specific class in AEM

Lets say I have one service like this:

 

@8220494(service = CurrenciesMongoWriter.class) public class CurrenciesMongoWriterImpl implements CurrenciesMongoWriter { ... ... }

How to add run mode to it so I can test it in dev, prod and etc.

此主题已关闭回复。
arunpatidar
Community Advisor
6月 3, 2022 7:19 上午 UTC

If you have run mode setup in AEM, then you can check run mode using

SLING API - https://developer.adobe.com/experience-manager/reference-materials/6-5/javadoc/org/apache/sling/settings/SlingSettingsService.html 

 

@Component
public class MyService {

    @Reference
    private SlingSettingsService slingSettingsService;

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

 

AND

If you want to resolve this service only for few run mode then you can use configurationPolicy property, that means this service will only be resolved if runmode specific repository Configurations are available

 

 

@Component(
service = CurrenciesMongoWriter.class,
immediate = true,
configurationPolicy = ConfigurationPolicy.REQUIRE)

 

Arun Patidar

5回复

Adobe Employee
6月 3, 2022 7:05 上午 UTC

Can you tell me what is your case and what you are trying to achieve ?

翻译
Level 2
6月 3, 2022 10:21 上午 UTC

I have this service:

 

@Component(service = CurrenciesMongoWriter.class)
public class CurrenciesMongoWriterImpl implements CurrenciesMongoWriter {

How to make it to run in dev mode for example throught configuration

翻译
arunpatidar
Community Advisor
Community Advisor
6月 3, 2022 7:19 上午 UTC

If you have run mode setup in AEM, then you can check run mode using

SLING API - https://developer.adobe.com/experience-manager/reference-materials/6-5/javadoc/org/apache/sling/settings/SlingSettingsService.html 

 

@Component
public class MyService {

    @Reference
    private SlingSettingsService slingSettingsService;

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

 

AND

If you want to resolve this service only for few run mode then you can use configurationPolicy property, that means this service will only be resolved if runmode specific repository Configurations are available

 

 

@Component(
service = CurrenciesMongoWriter.class,
immediate = true,
configurationPolicy = ConfigurationPolicy.REQUIRE)

 

翻译
Arun Patidar
DEBAL_DAS
New Member
6月 3, 2022 10:09 上午 UTC

https://sling.apache.org/apidocs/sling9/org/apache/sling/settings/SlingSettingsService.html , SlingSettingsService API has getRunModes() methods, it will help you to deal with run mode programatically.

翻译
Debal Das, Senior AEM Consultant
SantoshSai
Community Advisor
Community Advisor
6月 3, 2022 3:25 下午 UTC

Hi @stefanjank 

I have published blog on specific topic - Run Modes along with practical demo video, please visit this blog: https://www.techinnovia.com/run-modes/ 

Hope it helps!

Regards,
Santosh

翻译
Santosh Sai