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

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

Mark Solution

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

해결됨

Disable component on specific run mode

Avatar

Level 2

Hi everyone,

we have two special components in an OSGi Bundle. One should only run on the author instance and the other only on publish. Does anyone of you know how to disable each component on author/publish while activating the bundle?

We've tried this so far:

private static final String AUTHOR_RUN_MODE = "author"; @Activate public void activate(final ComponentContext context) throws Exception { @SuppressWarnings("rawtypes") final Dictionary properties = context.getProperties(); if (!slingSettingsService.getRunModes().contains(AUTHOR_RUN_MODE)) { final String componentName = (String) properties.get(ComponentConstants.COMPONENT_NAME); context.disableComponent(componentName); } }

Thanks in advance!

1 채택된 해결책 개

Avatar

정확한 답변 작성자:
Level 7

a better way would be to use OSGI bool  type property, read the value of that property (which will either be boolean true or false) and accordingly disable the OSGI component in activate method.

Now the value of the Bool property can be driven and forced to true or false as per your AEM run modes.. i.e. using runmode specific environment configuration file.

Follow the mentioned article to understand more on environment specific OSGI configuration - http://www.wemblog.com/2012/10/how-to-work-with-configurations-in-cq.html

Hope it helps.

- Runal

원본 게시물의 솔루션 보기

5 답변 개

Avatar

Level 7

Avatar

정확한 답변 작성자:
Level 7

a better way would be to use OSGI bool  type property, read the value of that property (which will either be boolean true or false) and accordingly disable the OSGI component in activate method.

Now the value of the Bool property can be driven and forced to true or false as per your AEM run modes.. i.e. using runmode specific environment configuration file.

Follow the mentioned article to understand more on environment specific OSGI configuration - http://www.wemblog.com/2012/10/how-to-work-with-configurations-in-cq.html

Hope it helps.

- Runal

Avatar

Level 10

Avatar

Employee

I prefer to do this via configuration, and not via code.

You can use: policy=ConfigurationPolicy.REQUIRE on @Component for this

When this is on your OSGi-component, this component will only be 'active' if there is a config supplied for it.

Avatar

Level 2

Thanks for your help. We didn't want to use a configuration file but it looks like that this is the best way so far to solve the problem.