我使用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.inv.DocumentType)并且我必须指定根标记,但我生成的 java 类中没有一个具有注释 XmlRootElement
请问如何配置我的工作以实现我的目标?
谢谢你。