问题
I have a WSDL and created a web service from it using CXF in Eclipse. The execution went fine: no output in the console, I don't know if there is a log somewhere but I could not find one. But in the service interface created, everywhere an XMLGregorianCalendar is used (as either parameter or return value), I get this error from Eclipse:
Abstract class javax.xml.datatype.XMLGregorianCalendar cannot be used as a runtime class because it is not extended by a non abstract class which is suitable as a runtime class
The use of XMLGregorialCalendar in the beans causes no problem, just in the interface. The WSDL was originally created by the same environment (so I am assuming is OK).
I have no idea what this error means! Is it a bug in CXF, a setting I set wrong, or some code I need to add now that the skeleton is created?
回答1:
That happens because you are using defaults. You can specify what type you want in bindings file.
Here is an example exert (notice how I tell to use java.util.Date class for "xs:dateTime"):
<jaxws:globalBindings>
<jaxws:javaType name="java.util.Date" xmlType="xs:dateTime"
parseMethod="org.apache.cxf.tools.common.DataTypeAdapter.parseDateTime"
printMethod="org.apache.cxf.tools.common.DataTypeAdapter.printDateTime" />
<jaxws:javaType name="java.lang.Integer" xmlType="xs:gYear" />
<jaxws:javaType name="java.lang.Integer" xmlType="xs:positiveInteger" />
<jaxws:javaType name="java.lang.Integer" xmlType="xs:integer" />
<jaxws:javaType name="java.lang.Integer" xmlType="xs:int" />
<jaxws:javaType name="java.util.Locale" xmlType="xs:language" />
</jaxws:globalBindings>
You can read more about JAXWS Customization and Customizing JAXB Bindings
回答2:
This is the actual binding file generated by CXF (if it helps anyone):
<jxb:bindings version="1.0" xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<jxb:bindings schemaLocation="example_schema1.xsd" node="/xs:schema">
<jxb:globalBindings xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<jxb:javaType name="java.util.Date" xmlType="xs:dateTime"
parseMethod="org.apache.cxf.xjc.runtime.DataTypeAdapter.parseDateTime"
printMethod="org.apache.cxf.xjc.runtime.DataTypeAdapter.printDateTime"/>
</jxb:globalBindings>
</jxb:bindings>
</jxb:bindings>
来源:https://stackoverflow.com/questions/22513359/web-service-code-created-by-cxf-is-not-legal-because-of-xmlgregoriancalendar