【问题标题】:Osgi Spring DM - Retrieve all beans by BundleOsgi Spring DM - 通过 Bundle 检索所有 bean
【发布时间】:2013-11-19 07:09:05
【问题描述】:

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

现在,我需要检索已安装包的应用程序上下文的所有 bean,检索包的应用程序上下文的最佳方法是什么?

 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

        }
}

【问题讨论】:

    标签: osgi eclipse-virgo spring-dm


    【解决方案1】:

    我用另一个 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" />
    

    【讨论】:

      猜你喜欢
      • 2016-01-01
      • 2023-04-05
      • 2012-04-18
      • 1970-01-01
      • 2014-09-09
      • 2015-11-26
      • 1970-01-01
      • 1970-01-01
      • 2023-04-07
      相关资源
      最近更新 更多