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)