質問

Eclipse Virgoを使用して、Bundlecontextawareを実装する豆のバンドルがあり、addbundleLelistenerを追加し、バンドルが起動または停止したときにイベントを正しく受け取ります。バンドルチェンジイベントによってバンドルがインストールされています。

これで、バンドルのアプリケーションコンテキストのすべての豆を取得する必要があります。バンドルのアプリケーションコンテキストを取得する最良の方法は何ですか?

 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

        }
}
役に立ちましたか?

解決

私は別のリスナーとの問題を解決します

  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" />
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top