Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

How to add run mode to specific class in AEM

Avatar

Level 2

Lets say I have one service like this:

 

@component(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.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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/sett... 

 

@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)

 

View solution in original post

5 Replies

Avatar

Employee

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

Avatar

Level 2

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

Avatar

Correct answer by
Community Advisor

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/sett... 

 

@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)

 

Avatar

Community Advisor

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