开发OSGi中遇到的一些问题记录

本文解决了在使用OSGi和SpringDM过程中遇到的三个常见问题:因jar包重复导致的系统错误、JUnit测试失败及SpringDM集成测试无法通过等问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题一:    

      在《深入理解OSGi---Equinox原理、应用与最佳实践》第325页至329页按照书上指示安装了Spring DM,并且运行了简单的例子,发现运行报错:

Caused by: java.lang.IllegalStateException: The System Bundle was updated. The framework must be restarted to finalize the configuration change
at org.eclipse.equinox.internal.simpleconfigurator.ConfigApplier.install(ConfigApplier.java:80)
at org.eclipse.equinox.internal.simpleconfigurator.SimpleConfiguratorImpl.applyConfiguration(SimpleConfiguratorImpl.java:191)
atorg.eclipse.equinox.internal.simpleconfigurator.SimpleConfiguratorImpl.applyConfiguration(SimpleConfiguratorImpl.java:205)
at org.eclipse.equinox.internal.simpleconfigurator.Activator.start(Activator.java:60)
at org.eclipse.osgi.internal.framework.BundleContextImpl$3.run(BundleContextImpl.java:771)
at org.eclipse.osgi.internal.framework.BundleContextImpl$3.run(BundleContextImpl.java:1)
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.osgi.internal.framework.BundleContextImpl.startActivator(BundleContextImpl.java:764)
... 25 more


    经过排查后是由于jar包重复导致,首先在项目名上右键点击“Run Configuration"打开运行时配置项:


     点击”Validate Bundles"按钮,弹出一个对话框,如下:


     可以看到有两个org.eclipse.osgi不同版本号的jar包存在,一个是sdk自带的,一个是安装Spring DM后出现的,我们只要把Spring DM路径下的这个jar包移除就行了。参考地址:https://stackoverflow.com/questions/5902291/eclipse-rcp-bundle-activation-error-the-system-bundle-was-updated

     

问题二:

      在第374页进行Eclipse JUnit Plug-in Test测试时,书上指出了那个错误是由于junit的jar包重复导致,让我们不要在”运行时配置项“的“Target Platform”里面选择com.springsource.junit,但是只操作这里还是不行,因为在unittest项目的元数据文件manifest.mf中定义了Require-Bundle:  com.springsource.junit,所以如果你如果不勾选这个jar,元数据文件就会一直冒红,并且程序也测试不通过,所以还要这么做一下:将“Require-Bundle:  com.springsource.junit”改为

Import-Package:   junit.framework  

因为导入com.springsource.junit包就是为了使用junit.framework ,而org.junit包里面也有junit.framework  ,所以才会重复。

    

问题三:

      在第378页至379页,将Eclipse JUnit Plug-in Test与Spring DM进行集成测试的时候,一直不成功,按照书上的做也不行,debug调试发现根本不走set方法,没有将HelloWorldService注入到实例中 ,不知道还要修改什么启动级别吗?有测试通过的,请告诉我一下。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值