歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Java使用JAX-WS來寫webservice時 Unable to create JAXBContext

Java使用JAX-WS來寫webservice時 Unable to create JAXBContext

日期:2017/3/1 9:46:23   编辑:Linux編程

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、自定義對象等等都沒問題,只是不能處理接口,那就在方法的參數和返回值上不要有接口就好了。

Copyright © Linux教程網 All Rights Reserved