How could I get BundleContext in Spring DM?

馋奶兔 提交于 2019-12-23 09:48:05

问题


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?

Thanks!

Regards!


回答1:


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();



回答2:


The Spring DM documentation says you should implement the BundleContextAware interface to get your bundle context. However, it also rightly explains you should hardly ever use it, and are perhaps better off using Spring DMs injection mechanisms if you need access to some service.



来源:https://stackoverflow.com/questions/6745004/how-could-i-get-bundlecontext-in-spring-dm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!