I have an OSGi bundle with multiple components, I want to activate/deactivate components from other components in same bundle.
I got BundleContext
from below code:
import aQute.bnd.annotation.component.Activate;
import aQute.bnd.annotation.component.Component;
import aQute.bnd.annotation.component.Deactivate;
@Activate
public void activate(Map<String, Object> properties) {
BundleContext bundleContext = FrameworkUtil.getBundle(MyComponent.class).getBundleContext();
}
But how can I get the ComponentContext
so that I can do enableComponent
or disableComponent
?
Simply inject the ComponentContext. You can then get the BundleContext as well as the config properties from it.
@Activate
public void activate(ComponentContext context)