OSGi与Spring DM整合问题,会的帮忙看看

plutowang 2011-03-15 04:42:28
由于公司需要开始学习OSGI。看了些文档,想写个小型demo跑跑看,但是程序跑不起来。运行时出现错误。
希望有经验的朋友半忙看看,也在学习这东西的朋友一起交流一下。

环境 Equinox容器 + Spring dm 1.21

下面上具体代码



//计算的接口
package com.zjhcsoft.compute;

public interface Compute {
public String comput(int x,int y);
}



接口的MANIFEST.MF文件


Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Comput Plug-in
Bundle-SymbolicName: com.zjhcsoft.compute
Bundle-Version: 1.0.0
Bundle-Vendor: ZJHCSOFT
Eclipse-LazyStart: true
Import-Package: org.osgi.framework;version="1.3.0"
Export-Package: com.zjhcsoft.compute




//接口的实现类,加法
package com.zjhcsoft.add;

import com.zjhcsoft.compute.Compute;

public class ComputeAdd implements Compute{

public String comput(int x, int y) {
System.out.println("做了加法");
return (x+y)+"";
}

}



加法实现类的MANIFEST.MF文件


Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Add Plug-in
Bundle-SymbolicName: com.zjhcsoft.add
Bundle-Version: 1.0.0
Bundle-Vendor: ZJHCSOFT
Eclipse-LazyStart: true
Import-Package: com.zjhcsoft.compute,
org.osgi.framework;version="1.3.0"




注册加法的服务的配置文件 addService.xml


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:osgi="http://www.springframework.org/schema/osgi"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/osgi
http://www.springframework.org/schema/osgi/spring-osgi.xsd
">
<bean id = "computeAdd" class="com.zjhcsoft.add.ComputeAdd" >
</bean>
<osgi:service id="computeAddService" interface="com.zjhcsoft.compute.Compute" ref="computeAdd" context-class-loader="service-provider"></osgi:service>
</beans>




//接口的实现类,减法

package com.zjhcsoft.mul;

import com.zjhcsoft.compute.Compute;

public class ComputeMul implements Compute {

public String comput(int x, int y) {
System.out.println("做了减法");
return (x-y)+"";
}

}


减法实现类的MANIFEST.MF文件


Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Mul Plug-in
Bundle-SymbolicName: com.zjhcsoft.mul
Bundle-Version: 1.0.0
Bundle-Vendor: ZJHCSOFT
Eclipse-LazyStart: true
Import-Package: com.zjhcsoft.compute,
org.osgi.framework;version="1.3.0"



注册减法服务的配置文件 mulService.xml


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:osgi="http://www.springframework.org/schema/osgi"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/osgi
http://www.springframework.org/schema/osgi/spring-osgi.xsd
">
<bean id = "computeMul" class="com.zjhcsoft.mul.ComputeMul" >
</bean>
<osgi:service id="computeMulService" interface="com.zjhcsoft.compute.Compute" ref="computeMul" context-class-loader="service-provider"></osgi:service>
</beans>




//服务的消费者

package com.zjhcsoft.clent;

import com.zjhcsoft.compute.Compute;
public class Clent {
public Clent(Compute compute){
System.out.println(compute.comput(6,5));
}
}



消费者的MANIFEST.MF文件


Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Clent Plug-in
Bundle-SymbolicName: com.zjhcsoft.clent
Bundle-Version: 1.0.0
Bundle-Vendor: ZJHCSOFT
Eclipse-LazyStart: true
Import-Package: com.zjhcsoft.compute,
org.osgi.framework;version="1.3.0"




//消费者的配置文件


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:osgi="http://www.springframework.org/schema/osgi"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/osgi
http://www.springframework.org/schema/osgi/spring-osgi.xsd
">
<bean id = "clent" class="com.zjhcsoft.clent.Clent">
<constructor-arg ref="computeService">
</constructor-arg>
</bean>
<osgi:reference id="computeService" interface="com.zjhcsoft.compute.Compute" cardinality="1..1" ></osgi:reference>
</beans>






下面是报错信息的一本分

严重: Pre refresh error
org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from URL [bundleentry://3470/META-INF/spring/reference.xml]; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:406)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:328)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:296)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
at org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext.loadBeanDefinitions(OsgiBundleXmlApplicationContext.java:221)
at org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext.loadBeanDefinitions(OsgiBundleXmlApplicationContext.java:130)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:123)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:423)
at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.startRefresh(AbstractDelegatedExecutionApplicationContext.java:191)
at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.stageOne(DependencyWaiterApplicationContextExecutor.java:212)
at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.refresh(DependencyWaiterApplicationContextExecutor.java:163)
at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.refresh(AbstractDelegatedExecutionApplicationContext.java:125)
at org.springframework.osgi.extender.internal.ContextLoaderListener$2.run(ContextLoaderListener.java:630)
at java.lang.Thread.run(Thread.java:595)
Caused by: java.lang.NullPointerException
at org.apache.xerces.impl.xs.traversers.XSDAttributeTraverser.traverseLocal(Unknown Source)
at org.apache.xerces.impl.xs.traversers.XSDAbstractTraverser.traverseAttrsAndAttrGrps(Unknown Source)
at org.apache.xerces.impl.xs.traversers.XSDComplexTypeTraverser.processComplexContent(Unknown Source)
at org.apache.xerces.impl.xs.traversers.XSDComplexTypeTraverser.traverseComplexTypeDecl(Unknown Source)
at org.apache.xerces.impl.xs.traversers.XSDComplexTypeTraverser.traverseLocal(Unknown Source)
at org.apache.xerces.impl.xs.traversers.XSDElementTraverser.traverseNamedElement(Unknown Source)
at org.apache.xerces.impl.xs.traversers.XSDElementTraverser.traverseGlobal(Unknown Source)
at org.apache.xerces.impl.xs.traversers.XSDHandler.traverseSchemas(Unknown Source)
at org.apache.xerces.impl.xs.traversers.XSDHandler.parseSchema(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaLoader.loadSchema(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.findSchemaGrammar(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.handleStartElement(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.startElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:75)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:382)
... 15 more
2011-3-15 16:32:56 org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor fail
















...全文
282 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
beeno 2011-08-24
  • 打赏
  • 举报
回复
我也在做这东西啊。。不懂
plutowang 2011-03-16
  • 打赏
  • 举报
回复
....沉了自己顶下、、、
plutowang 2011-03-15
  • 打赏
  • 举报
回复
补充下虽然出现了错误但是程序依然能够运行
plutowang 2011-03-15
  • 打赏
  • 举报
回复
纠结了很长时间不知道是为什么错希望会的朋友帮我纠正下,先谢谢了。

67,541

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧