【发布时间】:2017-04-16 01:44:10
【问题描述】:
有没有办法通过名称来停用给定的 OSGI 组件?
有 componentContext.disableComponent(componentName) 方法 - 但它只适用于同一个包的组件。
在不向给定捆绑包添加新服务以停用组件的情况下执行此操作的最佳实践解决方案是什么?
解决方案:
当使用例如菲利克斯这将是:
import org.apache.felix.scr.ScrService;
@Reference
private ScrService serviceComponentRuntime;
public void stopByName(final String componentName)
{
final org.apache.felix.scr.Component[] components = serviceComponentRuntime.getComponents(componentName);
for (final org.apache.felix.scr.Component component : components)
{
component.disable();
}
}
【问题讨论】:
标签: java osgi apache-felix