2013-08-21 68 views
1

我試圖使用外部綁定文件將XMLGregorianCalendar轉換爲java.util.Date,但它不轉換,它重新編譯XMLGregorianCalendar而不是java.util.Date,任何人都可以發現什麼我做錯了?我懷疑我的綁定文件中有些東西不對,因爲它在生成pojos時被拾取。綁定在被忽略的jaxws中的文件類型轉換

綁定文件:

<?xml version="1.0" encoding="UTF-8" ?> 
<jaxws:bindings version="2.0" 
    xmlns:jaxws="http://java.sun.com/xml/ns/jaxws" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 

    <jaxws:globalBindings> 

     <jaxws:javaType name="java.util.Date" xmlType="xsd:dateTime" 
      parseMethod="javax.xml.bind.DatatypeConverter.parseDateTime" 
      printMethod="javax.xml.bind.DatatypeConverter.printDateTime"/> 

     <jaxws:javaType name="java.util.Date" xmlType="xsd:time" 
      parseMethod="javax.xml.bind.DatatypeConverter.parseTime" 
      printMethod="javax.xml.bind.DatatypeConverter.printTime"/> 

     <jaxws:javaType name="java.util.Date" xmlType="xsd:date" 
      parseMethod="javax.xml.bind.DatatypeConverter.parseDate" 
      printMethod="javax.xml.bind.DatatypeConverter.printDate"/> 

    </jaxws:globalBindings> 

</jaxws:bindings> 

個人資料的pom.xml:

<profiles> 
    <profile> 
     <id>website</id> 
     <activation> 
     <activeByDefault>true</activeByDefault> 
     </activation> 
     <build> 
     <pluginManagement> 
      <plugins> 
      <plugin> 
       <groupId>org.jvnet.jax-ws-commons</groupId> 
       <artifactId>jaxws-maven-plugin</artifactId> 
       <version>2.2</version> 
      </plugin> 
      </plugins> 
     </pluginManagement> 
     <plugins> 
      <plugin> 
      <groupId>org.jvnet.jax-ws-commons</groupId> 
      <artifactId>jaxws-maven-plugin</artifactId> 
      <executions> 
       <execution> 
       <id>wsimport</id> 
       <phase>generate-sources</phase> 
       <goals> 
        <goal>wsimport</goal> 
       </goals> 
       <configuration> 
        <packageName>za.co.website.application.model</packageName> 
        <sourceDestDir>src/main/java</sourceDestDir> 
        <wsdlFiles> 
        <wsdlFile> 
         ${basedir}/src/jaxws/wsdl/Application.wsdl 
        </wsdlFile> 
        </wsdlFiles> 
        <target>2.1</target> 
        <bindingFiles> 
        <bindingFile> 
         ${basedir}/src/jaxws/binding/bindings.xml 
        </bindingFile> 
        </bindingFiles>     
       </configuration> 
       </execution> 
      </executions> 
      </plugin> 
     </plugins> 
     </build> 
    </profile> 
    </profiles> 

使用-X調用構建腳本時,我表明它正在拿起 MVN全新安裝-DskipTest -X

... 
[DEBUG] The wsdl File is '...\website-application/src/jaxws/wsdl/Application.wsdl' from 'file:/.../website-application/src/jaxws/wsdl/Application.wsdl' 
[INFO] Processing: file:/.../website-application/src/jaxws/wsdl/Application.wsdl 
[DEBUG] jaxws:wsimport args: [-keep, -s, ...\website-application\src\main\java, -encoding, UTF-8, -Xnocompile, -p, za.co.website.application.model, -target, 2.1, -b, ...\website-application\src\jaxws\binding\bindings.xml] 
[INFO] jaxws:wsimport args: [-keep, -s, ...\website-application\src\main\java, -encoding, UTF-8, -Xnocompile, -p, za.co.website.application.model, -target, 2.1, -b, ...\website-application\src\jaxws\binding\bindings.xml, file:/.../website-application/src/jaxws/wsdl/Application.wsdl] 
parsing WSDL... 
... 

回答

1

添加node="wsdl:definitions/wsdl:types/xs:schema"jaxws:globalBindings應該這樣做,所以綁定文件應該如下所示:

<?xml version="1.0" encoding="UTF-8" ?> 
<jaxws:bindings version="2.0" 
     xmlns:jaxws="http://java.sun.com/xml/ns/jaxws" 
     xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
     node="wsdl:definitions/wsdl:types/xs:schema"> 

    <jaxws:globalBindings> 
     <jaxws:javaType name="java.util.Date" xmlType="xsd:dateTime" 
      parseMethod="javax.xml.bind.DatatypeConverter.parseDateTime" 
      printMethod="javax.xml.bind.DatatypeConverter.printDateTime"/> 
     <jaxws:javaType name="java.util.Date" xmlType="xsd:time" 
      parseMethod="javax.xml.bind.DatatypeConverter.parseTime" 
      printMethod="javax.xml.bind.DatatypeConverter.printTime"/> 
     <jaxws:javaType name="java.util.Date" xmlType="xsd:date" 
      parseMethod="javax.xml.bind.DatatypeConverter.parseDate" 
      printMethod="javax.xml.bind.DatatypeConverter.printDate"/> 
    </jaxws:globalBindings> 
</jaxws:bindings>