我有以下代码
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class SamplePojo {
private Serializable id;
private String name;
public Serializable getId() {
return id;
}
public void setId(Serializable id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
和一个简单的网络服务界面,
@WebService
public interface SampleManagementService {
@WebMethod
@WebResult(name = "samplePojo")
public SamplePojo update(@WebParam(name = "samplePojo") SamplePojo pojo) throws SampleException;
}
我正在使用 CXF-2.3.6 并org.apache.cxf.tools.java2ws.JavaToWS
从 java 代码生成 WSDL。当我运行命令时
java2ws -verbose -o sample.wsdl -wsdl -frontend jaxws com.test.cxf.webservice.sample.SampleManagementService
我得到以下异常
cxfJavaToWSDL:
[java] java2ws -verbose -o sample.wsdl -wsdl -frontend jaxws com.test.cxf.webservice.sample.SampleManagementService
[java] java2ws - Apache CXF 2.3.6
[java]
[java] May 29, 2012 4:51:48 PM org.apache.cxf.service.factory.ReflectionServiceFactoryBean buildServiceFromClass
[java] INFO: Creating Service {http://sample.webservice.cxf.test.com/}SampleManagementServiceService from class com.test.cxf.webservice.sample.SampleManagementService
[java] Error: java.lang.RuntimeException: org.apache.cxf.service.factory.ServiceConstructionException
[java]
[java] java.lang.RuntimeException: org.apache.cxf.service.factory.ServiceConstructionException
[java] at org.apache.cxf.frontend.AbstractServiceFactory.createService(AbstractServiceFactory.java:80)
[java] at org.apache.cxf.tools.java2wsdl.processor.JavaToWSDLProcessor.process(JavaToWSDLProcessor.java:101)
[java] at org.apache.cxf.tools.java2ws.JavaToWSContainer.processWSDL(JavaToWSContainer.java:110)
[java] at org.apache.cxf.tools.java2ws.JavaToWSContainer.execute(JavaToWSContainer.java:75)
[java] at org.apache.cxf.tools.common.toolspec.ToolRunner.runTool(ToolRunner.java:103)
[java] at org.apache.cxf.tools.common.toolspec.ToolRunner.runTool(ToolRunner.java:58)
[java] at org.apache.cxf.tools.common.toolspec.ToolRunner.runTool(ToolRunner.java:40)
[java] at org.apache.cxf.tools.java2ws.JavaToWS.run(JavaToWS.java:77)
[java] at org.apache.cxf.tools.java2ws.JavaToWS.main(JavaToWS.java:45)
[java] Caused by: org.apache.cxf.service.factory.ServiceConstructionException
[java] at org.apache.cxf.jaxb.JAXBDataBinding.initialize(JAXBDataBinding.java:341)
[java] at org.apache.cxf.service.factory.AbstractServiceFactoryBean.initializeDataBindings(AbstractServiceFactoryBean.java:86)
[java] at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.buildServiceFromClass(ReflectionServiceFactoryBean.java:442)
[java] at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.buildServiceFromClass(JaxWsServiceFactoryBean.java:682)
[java] at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.initializeServiceModel(ReflectionServiceFactoryBean.java:505)
[java] at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.create(ReflectionServiceFactoryBean.java:242)
[java] at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.create(JaxWsServiceFactoryBean.java:202)
[java] at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:101)
[java] at org.apache.cxf.frontend.AbstractServiceFactory.createService(AbstractServiceFactory.java:78)
[java] ... 8 more
[java] Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 3 counts of IllegalAnnotationExceptions
[java] Adapter com.test.cxf.webservice.sample.SerializableAdapter is not applicable to the field type java.io.Serializable.
[java] this problem is related to the following location:
[java] at @javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter(type=class javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter$DEFAULT, value=class com.test.cxf.webservice.sample.SerializableAdapter)
[java] at private java.io.Serializable com.test.cxf.webservice.sample.SamplePojo.id
[java] at com.test.cxf.webservice.sample.SamplePojo
[java] at private com.test.cxf.webservice.sample.SamplePojo com.test.cxf.webservice.sample.jaxws_asm.Update.samplePojo
[java] at com.test.cxf.webservice.sample.jaxws_asm.Update
[java] java.io.Serializable is an interface, and JAXB can't handle interfaces.
[java] this problem is related to the following location:
[java] at java.io.Serializable
[java] at private java.io.Serializable com.test.cxf.webservice.sample.SamplePojo.id
[java] at com.test.cxf.webservice.sample.SamplePojo
[java] at private com.test.cxf.webservice.sample.SamplePojo com.test.cxf.webservice.sample.jaxws_asm.Update.samplePojo
[java] at com.test.cxf.webservice.sample.jaxws_asm.Update
[java] java.io.Serializable does not have a no-arg default constructor.
[java] this problem is related to the following location:
[java] at java.io.Serializable
[java] at private java.io.Serializable com.test.cxf.webservice.sample.SamplePojo.id
[java] at com.test.cxf.webservice.sample.SamplePojo
[java] at private com.test.cxf.webservice.sample.SamplePojo com.test.cxf.webservice.sample.jaxws_asm.Update.samplePojo
[java] at com.test.cxf.webservice.sample.jaxws_asm.Update
[java]
[java] at com.sun.xml.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:102)
[java] at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:472)
[java] at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:302)
[java] at com.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1140)
我试图创造SerializableAdapter
,但没有运气。谁能告诉我处理Serializable
参数传递的正确方法是什么?