【问题标题】:Spring DM (Dynamics Modules), OSGI and Greenpages applicationSpring DM(动态模块)、OSGI 和 Greenpages 应用程序
【发布时间】:2015-12-29 11:24:11
【问题描述】:

“Greenpages 应用程序”是 Eclipse Virgo 站点中提供的示例 Web 应用程序,它提供了一起使用 OSGI 和 Spring DM 的示例,并且可以部署在 Virgo 容器中。请参阅:http://www.eclipse.org/virgo/samples/。我能够毫无错误地运行该应用程序。但是一旦我尝试实现 org.springframework.osgi.context.event.OsgiBundleApplicationContextListener 接口,一切都出错了,我开始收到这个错误:

java.lang.IllegalArgumentException:必需的属性“bundleContext” 尚未设置

OsgiBundleApplicationContextListener 接口提供了一种监听 BundleContext 事件的方法。见:http://docs.spring.io/osgi/docs/current/api/org/springframework/osgi/context/event/OsgiBundleApplicationContextListener.html

我的代码:

公共类 ApplicationContextObserver 实现 OsgiBundleApplicationContextListener { 私有瞬态int countRefreshed = 0; 私有瞬态 int countClosed = 0;

public void onOsgiApplicationEvent(OsgiBundleApplicationContextEvent evt) {
    if(evt instanceof
            OsgiBundleContextRefreshedEvent) {
        countRefreshed++;
    } else if(evt instanceof
            OsgiBundleContextClosedEvent) {
        countClosed++;
    }
}
public int getCountRefreshed() {
    return countRefreshed;
}
public int getCountClosed() {
    return countClosed;
}

}

还有声明的 bean:

<bean id="ApplicationContextObserver" class="greenpages.ApplicationContextObserver" />
<osgi:service ref="ApplicationContextObserver" interface="org.springframework.osgi.context.event.OsgiBundleApplicationContextListener" />      

最糟糕的是,有时这个错误根本不会出现,但是当我在容器中部署另一个包时,不会调用侦听器。

出了什么问题(如果可能,您能否附上一个使用 Virgo Container、SpringDM 和此侦听器的运行示例)?

【问题讨论】:

  • Spring DM 已经死了很长时间了,你应该使用 Eclipse Virgo 类而不是旧的 Spring DM 类。
  • 好的。我可以从类路径中删除 SpringDM,但我需要保留 Spring 核心本身,因为我的项目是基于 Spring 的。我需要如何使用来自 Eclipse Virgo 的类(以及我需要如何以正确的方式做到这一点)以使用 BundleContext 侦听器使一切正常工作?你能提供任何maven项目示例吗?谢谢!!

标签: spring osgi eclipse-virgo spring-dm


【解决方案1】:
猜你喜欢
  • 2012-04-18
  • 2023-04-07
  • 2011-11-08
  • 2014-03-11
  • 2014-09-09
  • 2020-12-10
  • 2023-04-05
  • 2012-07-02
  • 2015-11-26
相关资源
最近更新 更多