如何在Spring DM中获取BundleContext? [英] How could I get BundleContext in Spring DM?
问题描述
我是Spring DM的新用户,我想访问Bundlecontext.我的问题是我与Activator捆绑在一起,但是没有xml配置文件.我无法触摸此捆绑包,然后需要访问BundleContext和serviceReference才能在捆绑包中获取服务.我在捆绑包中使用Spring DM.那么,我如何获得BundleContext?
I am newly on Spring DM and I would like to access Bundlecontext. My problem is that I have a bundle with Activator, but it does not have xml config file. I cannot touch this bundle, then I need to access to BundleContext and serviceReference to obtain the service in my bundle. I am using Spring DM in my bundle. So, how could I get BundleContext?
谢谢!
致谢!
推荐答案
如果不想依赖DM及其机制,则一种方法是实现BundleContextAware
,另一种方法是:
One way is to implement BundleContextAware
and the other one, if you don't want to rely on DM and its mechanisms:
BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
这篇关于如何在Spring DM中获取BundleContext?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!