How could I get BundleContext in Spring DM?
Asked Answered
T

2

5

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!

Tombaugh answered 19/7, 2011 at 9:27 Comment(0)
B
8

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();
Beguile answered 19/3, 2012 at 15:19 Comment(0)
D
0

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.

Dow answered 19/7, 2011 at 9:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.