title: Access application context from BundleContextAware class
body: <p>I have created an osgi bundle from an existing legacy war.  The app has a class that implements the spring interface ApplicationContextAware, it then uses the context to programmatically get beans (not sure why but this needs refactoring eventually). The app now uses OsgiBundleXmlApplicationContext, but I believe that there is an issue with using this whereby the setApplicationContext method does not get called in any classes implementing ApplicationContextAware, so now the context in this class is always null.  </p>
  
  <p>So as a workaround I have implemented BundleContextAware so that I can get a reference to the published context and get access to the beans that way.  This works ok however the only bean on the context is warDeployer (should mention that I am using the spring dm bundle spring-extender to deploy the war).  The bundle present on the context is my bundle so I cannot see why the context that I am getting has none of my beans on it.  The code I have to get the application context is:
  <code></p>
  
  <p>ServiceReference ref =  bundleContext.getServiceReference(ApplicationContext.class.getName());
    applicationContext = (OsgiBundleXmlApplicationContext) bundleContext.getService(ref);
  </code></p>
  
  <p>I can see in the logs that much of my context is getting created so I can't see why they are not on the context I am getting.  </p>
  
  <p>Can anyone advise as to what is wrong?  I understand that this approach is a bit hacky, but it's temporary until the existing code is refactored.</p>
  
  <p>Thanks in advance.</p>
  
  <p>Barry</p>