您的位置:首页 > 其它

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

2018-01-18 17:24 459 查看
问题一:    
      在《深入理解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注入到实例中 ,不知道还要修改什么启动级别吗?有测试通过的,请告诉我一下。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  OSGi