Osgi Spring DM - 通过Bundle检索所有bean

时间:2013-11-07 15:06:10

标签: osgi eclipse-virgo spring-dm

使用Eclipse Virgo我有一个带有实现BundleContextAware的bean的Bundle,我添加了一个addBundleListener并在Bundle启动或停止时正确接收事件,这没关系。并通过bundleChanged事件安装了一个包。

现在,我需要检索所安装的bundle的应用程序上下文的所有bean,这是检索bundle的应用程序上下文的最佳方法吗?

 public class PluginManager implements BundleContextAware {
               private BundleContext bundleContext;
          @Override
          public void setBundleContext(BundleContext bundleContext) {
            this.bundleContext = bundleContext;
            bundleContext.addBundleListener(this);
           }

              @Override
         public void bundleChanged(BundleEvent event) {


           Bundle bundle = event.getBundle();

    //HOW TO DO TO GET ALL BEANS OF BUNDLE

        }
}

1 个答案:

答案 0 :(得分:0)

我用另一个Listener

解决了我的问题
  public class PluginManager implements BundleContextAware,OsgiBundleApplicationContextListener {
           private BundleContext bundleContext;
      @Override
      public void setBundleContext(BundleContext bundleContext) {
        this.bundleContext = bundleContext;
        bundleContext.addBundleListener(this);
       }

          @Override
     public void bundleChanged(BundleEvent event) {


       Bundle bundle = event.getBundle();

      //NOW use this method to receive destroy event

    }
    @Override
public void onOsgiApplicationEvent(OsgiBundleApplicationContextEvent event) {

             Bundle bundle = event.getBundle();

    PluginBundleDescriptor pluginBundleDescriptor = new PluginBundleDescriptor();
    pluginBundleDescriptor.setId(bundle.getBundleId());
    pluginBundleDescriptor.setName(bundle.getSymbolicName());
    pluginBundleDescriptor.setApplicationContext(event
            .getApplicationContext());

} }

并使用OsgiBundleApplicationContextListener接口发布服务(这很重要)

 <osgi:service id="bundleContextTrackerOSGi" ref="coreModuleManager"
interface="org.springframework.osgi.context.event.OsgiBundleApplicationContextListener" />