1

Eclipse Virgo を使用して、BundleContextAware を実装する Bean を含むバンドルがあり、addBundleListener を追加して、バンドルが開始または停止されたときにイベントを正しく受け取ります。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

        }
}
4

1 に答える 1

0

別のリスナーで問題を解決する

  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" />
于 2013-11-08T11:34:30.397 に答える