简体   繁体   English

两个类具有相同的XML类型名称maven jaxb插件,Spring

[英]Two classes have the same XML type name maven jaxb plugin , Spring

I have some control over some of my schemas so my question is a little different than the ones similar to this. 我对我的一些模式有一些控制权,所以我的问题与类似的模式略有不同。 I have three schemas, c.xsd imports b.xsd, b.xsd imports a.xsd. 我有三个模式,c.xsd导入b.xsd,b.xsd导入a.xsd。 All three have different namespaces. 这三个都有不同的命名空间。

<?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>

Class A is generated twice, once in org.testing.common and once in org.testing.c and both of them both have the same namespace @XmlType(name = "ClassA", namespace = "ANamespace". However, Spring doesn't know which one to use. Do I really need ClassA generated twice? A类生成两次,一次在org.testing.common中,一次在org.testing.c中,两者都有相同的命名空间@XmlType(name =“ClassA”,namespace =“ANamespace”。但是,Spring没有'知道使用哪一个。我真的需要ClassA生成两次吗?

Here is my pom.xml: 这是我的pom.xml:

<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>

Run the generation goal once and specify your namespace to package mapping in your binding file instead of in the plugin config: 运行生成目标一次,并在绑定文件中而不是在插件配置中指定您的命名空间到包映射:

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM