0

我使用JAXB xjc工具从我的多个 xsd 文件生成 java 类(我使用在线工具从我的 xml 文件生成 xsd 文件)。

我的问题是我不知道如何配置我的 context.xml 以使其读取给定的所有类(和 xml),并且只生成一个最终的大 xml 文件。

这是我的 context.xml:

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:batch="http://www.springframework.org/schema/batch" xmlns:task="http://www.springframework.org/schema/task"
xmlns:util="http://www.springframework.org/schema/util" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/batch
    http://www.springframework.org/schema/batch/spring-batch-2.2.xsd
    http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
    http://www.springframework.org/schema/util 
    http://www.springframework.org/schema/util/spring-util-3.2.xsd">
<import resource="../config/context.xml" />
<batch:job id="bghJob" parent="simpleJob">
    <batch:step id="step1">
        <batch:tasklet>
            <batch:chunk reader="multiResourceReader" writer="xmlItemWriter"
                commit-interval="1" />
        </batch:tasklet>
    </batch:step>
</batch:job>

<bean id="multiResourceReader"
    class=" org.springframework.batch.item.file.MultiResourceItemReader">
    <property name="resources" value="classpath:xml/*.xml" />
    <property name="delegate" ref="xmlItemReader" />
</bean>

<bean id="xmlItemReader" class="org.springframework.batch.item.xml.StaxEventItemReader">
    <property name="unmarshaller" ref="invoiceUnMarshaller" />
    <property name="fragmentRootElementName" value="DocumentType" />
</bean>

<bean id="invoiceUnMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
    <property name="classesToBeBound">
        <value>com.xxx.generatedByJaxb.inv.DocumentType</value>
    </property>
</bean>

<bean id="xmlItemWriter" class="org.springframework.batch.item.xml.StaxEventItemWriter">
    <property name="resource" value="file:xml/outputs/Facture.xml" />
    <property name="marshaller" ref="invoiceMarshaller" />
    <property name="rootTagName" value="Facture" />
</bean>

<bean id="invoiceMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
    <property name="classesToBeBound">
        <value>com.xxx.generatedByJaxb.inv.DocumentType</value>
    </property>
</bean>

似乎我只能读取一个类(例如 com.xxx.generatedByJaxb.in​​v.DocumentType)并且我必须指定根标记,但我生成的 java 类中没有一个具有注释 XmlRootElement

请问如何配置我的工作以实现我的目标?

谢谢你。

4

1 回答 1

1

只需使用该contextPath属性:

<property name="contextPath"
   value="com.xxx.generatedByJaxb.inv:com.yyy.generatedByJaxb.inv"/>

这是一个相关包的列表, -:分隔。

还要检查其他属性,它们可能很方便。

于 2014-10-14T12:00:06.403 回答