2017-01-09 2 views
0

내 스키마에 대한 일부 제어 권한이 있으므로 내 질문과 비슷합니다. 나는 3 개의 스키마, c.xsd imports b.xsd, b.xsd imports a.xsd를 가지고있다. 세 가지 모두 네임 스페이스가 다릅니다.두 클래스의 XML 유형 이름은 maven jaxb plugin과 동일합니다. Spring

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" xmlns="ANamespace" targetNamespace="ANamespace" version="1.0" jaxb:extensionBindingPrefixes="xjc" jaxb:version="1.0"> 
<xs:complexType name="ClassA"> 
    <xs:sequence> 
     <xs:element name="classAFieldName" type="xs:string" minOccurs="0"> 
     </xs:element> 
    </xs:sequence> 
</xs:complexType> 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" xmlns="BNamespace" targetNamespace="BNamespace" version="1.0" jaxb:extensionBindingPrefixes="xjc" jaxb:version="1.0"> 


<xs:import namespace="ANamespace" schemaLocation="a.xsd"/> 

<xs:complexType name="ClassB"> 
    <xs:sequence> 
     <xs:element name="classBFieldName" type="xs:string" minOccurs="0"> 
     </xs:element> 
    </xs:sequence> 
</xs:complexType> 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" xmlns="CNamespace" targetNamespace="CNamespace" version="1.0" jaxb:extensionBindingPrefixes="xjc" jaxb:version="1.0"> 


<xs:import namespace="BNamespace" schemaLocation="b.xsd"/> 

<xs:complexType name="ClassC"> 
    <xs:sequence> 
     <xs:element name="classCFieldName" type="xs:string" minOccurs="0"> 
     </xs:element> 
    </xs:sequence> 
</xs:complexType> 

A 등급은 한 번 org.testing.common에 한 번 org.testing.c과 둘, 두 번 생성 둘 다 같은 네임 스페이스 @XmlType (name = "ClassA", 네임 스페이스 = "ANamespace".) 그러나 Spring은 사용할 하나를 알지 못합니다. ClassA가 두 번 생성 되었습니까?

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
<modelVersion>4.0.0</modelVersion> 

<groupId>com.wfs.fi.stp</groupId> 
<artifactId>testing</artifactId> 
<version>0.0.1-SNAPSHOT</version> 
<packaging>jar</packaging> 

<name>testing</name> 
<url>http://maven.apache.org</url> 

<properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
</properties> 
<build> 
    <plugins> 
     <plugin> 
      <groupId>org.eclipse.m2e</groupId> 
      <artifactId>lifecycle-mapping</artifactId> 
      <version>1.0.0</version> 
      <configuration> 
       <lifecycleMappingMetadata> 
        <pluginExecutions> 
         <pluginExecution> 
          <pluginExecutionFilter> 
           <groupId>org.jvnet.jaxb2.maven2</groupId> 
           <artifactId>maven-jaxb2-plugin</artifactId> 
           <versionRange>[0.13.1,)</versionRange> 
           <goals> 
            <goal>generate</goal> 
           </goals> 
          </pluginExecutionFilter> 
          <action> 
           <configurator> 
            <id>org.eclipselabs.m2e.jaxb2.connector.Jaxb2JavaProjectConfigurator</id> 
           </configurator> 
          </action> 
         </pluginExecution> 
        </pluginExecutions> 
       </lifecycleMappingMetadata> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.jvnet.jaxb2.maven2</groupId> 
      <artifactId>maven-jaxb2-plugin</artifactId> 
      <version>0.13.1</version> 
      <executions> 
       <execution> 
        <id>A</id> 
        <goals> 
         <goal>generate</goal> 
        </goals> 
        <configuration> 
         <schemaDirectory>src/main/resources</schemaDirectory> 
         <schemaIncludes> 
          <include>a.xsd</include> 
         </schemaIncludes> 
         <bindingIncludes> 
          <include>a.xjb</include> 
         </bindingIncludes> 
         <generatePackage>org.testing.common</generatePackage> 
         <generateDirectory>${project.build.directory}/common_generated</generateDirectory> 
         <episode>true</episode> 
         <episodeFile>${project.build.directory}/common.episode</episodeFile> 
         <extension>true</extension> 
         <verbose>true</verbose> 
         <properties> 
          <property> 
           <name>javax.xml.accessExternalSchema</name> 
           <value>all</value> 
          </property> 
          <property> 
           <name>javax.xml.accessExternalDTD</name> 
           <value>all</value> 
          </property> 
         </properties> 
         <args> 
          <arg>-npa</arg> 
         </args> 
         <disableXmlSecurity>true</disableXmlSecurity> 
         <accessExternalSchema>all</accessExternalSchema> 
         <accessExternalDTD>all</accessExternalDTD> 
        </configuration> 
       </execution> 
       <execution> 
        <id>B</id> 
        <goals> 
         <goal>generate</goal> 
        </goals> 
        <configuration> 
         <schemaDirectory>src/main/resources</schemaDirectory> 
         <schemaIncludes> 
          <include>b.xsd</include> 
         </schemaIncludes> 
         <generatePackage>org.testing.b</generatePackage> 
         <generateDirectory>${project.build.directory}/b_generated</generateDirectory> 
         <bindingIncludes> 
          <include>b.xjb</include> 
         </bindingIncludes> 
         <episode>true</episode> 
         <args> 
          <arg>-b</arg> 
          <arg>${project.build.directory}/common.episode</arg> 
          <arg>-npa</arg> 
         </args> 
         <episodeFile>${project.build.directory}/b.episode</episodeFile> 
         <extension>true</extension> 
         <verbose>true</verbose> 
         <disableXmlSecurity>true</disableXmlSecurity> 
         <accessExternalSchema>all</accessExternalSchema> 
         <accessExternalDTD>all</accessExternalDTD> 
        </configuration> 
       </execution> 

       <execution> 
        <id>C</id> 
        <goals> 
         <goal>generate</goal> 
        </goals> 
        <configuration> 
         <schemaDirectory>src/main/resources</schemaDirectory> 
         <schemaIncludes> 
          <include>c.xsd</include> 
         </schemaIncludes> 
         <generatePackage>org.testing.c</generatePackage> 
         <generateDirectory>${project.build.directory}/c_generated</generateDirectory> 
         <bindingIncludes> 
          <include>c.xjb</include> 
         </bindingIncludes> 
         <args> 
          <arg>-b</arg> 
          <arg>${project.build.directory}/b.episode</arg> 

          <arg>-npa</arg> 
         </args> 
         <plugins> 
          <plugin> 
           <groupId>org.jvnet.jaxb2_commons</groupId> 
           <artifactId>jaxb2-basics</artifactId> 
           <version>0.6.4</version> 
          </plugin> 
         </plugins> 
         <extension>true</extension> 
         <verbose>true</verbose> 
         <disableXmlSecurity>true</disableXmlSecurity> 
         <accessExternalSchema>all</accessExternalSchema> 
         <accessExternalDTD>all</accessExternalDTD> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 

답변

0

한 번 생성 목표를 실행하고 바인딩 파일에 대신 플러그인 설정에 매핑을 패키지로 네임 스페이스를 지정합니다 :

<jaxb:bindings 
     xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd" 
     version="2.1"> 

    <jaxb:bindings schemaLocation="a.xsd"> 
     <jaxb:schemaBindings> 
      <jaxb:package name="org.testing.common"/> 
     </jaxb:schemaBindings> 
    </jaxb:bindings> 
    <jaxb:bindings schemaLocation="b.xsd"> 
     <jaxb:schemaBindings> 
      <jaxb:package name="org.testing.b"/> 
     </jaxb:schemaBindings> 
    </jaxb:bindings> 
    <jaxb:bindings schemaLocation="c.xsd"> 
     <jaxb:schemaBindings> 
      <jaxb:package name="org.testing.c"/> 
     </jaxb:schemaBindings> 
    </jaxb:bindings> 

</jaxb:bindings> 
다음

내 pom.xml 파일입니다
+0

정말 아무것도 바뀌지 않았습니다. ClassA.java가 두 번 생성됩니다. org.testing.common과 @XmlType (name = "")에서 생성 된 @XmlType (name = "ClassA", namespace = "ANamespace", propOrder = { "classAFieldName" } ClassA ", namespace ="ANamespace ", propOrder = { "classAFieldName " }가 org.testing.c에서 생성되었습니다. Spring의 문제점은 둘 다 ANamespace에 있다는 것입니다. – noobjob

+0

_A_ 및 _B_ 목표 설정과''설정을 제거 했습니까? 사용중인 플러그인에 익숙하지 않습니다. 하지만 최선의 연습 페이지는 "패키지 생성"사용에 대해 경고합니다 (https://github.com/highsource/maven-jaxb2-plugin/wiki/Configure-Target-Packages-in-Binding-Files). – teppic

+0

알았어, 나는 그것을 시도했다 (A와 B e를 제거한다. xecutions 및 config)를 작성한 다음 모든 네임 스페이스에 대해 하나의 바인딩 파일을 작성했습니다. 흥미로운 점은 모든 것이 여전히 두 번 생성되지만 ClassA/B/C는 @XmlType 주석에 anamespace/bnamespace/cnamespace Java 패키지 이름과 NO namespace 속성을 가지고 있다는 것입니다. 이 파일들을 무시한 채 봄을 혼동해서는 안된다. 당신의 도움을 주셔서 감사합니다! – noobjob