Java使用JAX-WS来写webservice时 Unable to create JAXBContext


webservice,作为web开发人员来说必须掌握的一门技术,它的好处这里就不多说了,MyEclipse中自带了一种生成webservice的方法,使用JAX-WS,如果我没有弄错的话,它需要javaEE5.0、JDK1.5以上,了解完这些就开始写接口方法。各种随心所欲。不料在用MyEclipse生成webservice时出现错误了,生成不了,错误信息如下“ An internal error occurred during: "Generating JAX-WS Web Services". Unable to create JAXBContext ”  ,错误堆栈如下:

javax.xml.ws.WebServiceException: Unable to create JAXBContext
 at com.sun.xml.ws.model.AbstractSEIModelImpl.createJAXBContext(AbstractSEIModelImpl.java:158)
 at com.sun.xml.ws.model.AbstractSEIModelImpl.postProcess(AbstractSEIModelImpl.java:87)
 at com.sun.xml.ws.model.RuntimeModeler.buildRuntimeModel(RuntimeModeler.java:262)
 at com.sun.tools.ws.wscompile.WsgenTool.buildModel(WsgenTool.java:225)
 at com.sun.tools.ws.wscompile.WsgenTool.run(WsgenTool.java:124)
 at com.genuitec.eclipse.ws.jaxws.JaxWSBUJob.wsGen(JaxWSBUJob.java:224)
 at com.genuitec.eclipse.ws.jaxws.JaxWSBUJob.run(JaxWSBUJob.java:124)
 at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
Caused by: java.security.PrivilegedActionException: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions
java.sql.ResultSet is an interface, and JAXB can't handle interfaces.
 this problem is related to the following location:
  at java.sql.ResultSet
  at private java.sql.ResultSet com.bjjdsy.service.jaxws.TestABCResponse._return
  at com.bjjdsy.service.jaxws.TestABCResponse
java.sql.ResultSet does not have a no-arg default constructor.
 this problem is related to the following location:
  at java.sql.ResultSet
  at private java.sql.ResultSet com.bjjdsy.service.jaxws.TestABCResponse._return
  at com.bjjdsy.service.jaxws.TestABCResponse

 at java.security.AccessController.doPrivileged(Native Method)
 at com.sun.xml.ws.model.AbstractSEIModelImpl.createJAXBContext(AbstractSEIModelImpl.java:148)
 ... 7 more
Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions
java.sql.ResultSet is an interface, and JAXB can't handle interfaces.
 this problem is related to the following location:
  at java.sql.ResultSet
  at private java.sql.ResultSet com.bjjdsy.service.jaxws.TestABCResponse._return
  at com.bjjdsy.service.jaxws.TestABCResponse
java.sql.ResultSet does not have a no-arg default constructor.
 this problem is related to the following location:
  at java.sql.ResultSet
  at private java.sql.ResultSet com.bjjdsy.service.jaxws.TestABCResponse._return
  at com.bjjdsy.service.jaxws.TestABCResponse

 at com.sun.xml.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:102)
 at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:438)
 at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:286)
 at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:139)
 at com.sun.xml.bind.api.JAXBRIContext.newInstance(JAXBRIContext.java:105)
 at com.sun.xml.ws.model.AbstractSEIModelImpl$1.run(AbstractSEIModelImpl.java:153)
 at com.sun.xml.ws.model.AbstractSEIModelImpl$1.run(AbstractSEIModelImpl.java:149)
 ... 9 more

真心让人郁闷,尤其是刚开始搞webservice的时候。其实仔细阅读一下堆栈信息就会发现,说 ResultSet是一个接口,而JAXB不能处理接口。记得网上有人说 JAX-WS只支持基本数据类型,int、String等,其实不是的,JAX支持的数据类型很多,List、HashMap、自定义对象等等都没问题,只是不能处理接口,那就在方法的参数和返回值上不要有接口就好了。

相关内容

    暂无相关文章