Reader(StaxEventItemReader)Resource to Domain对象 [英] Reader(StaxEventItemReader) Resource to Domain object

查看:231
本文介绍了Reader(StaxEventItemReader)Resource to Domain对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将输入资源位置作为String传递给域对象的字段。

我的配置如下所示:

I want to pass the input resource location as a String to a field of the domain object.
My configuration looks like this:

<bean id="step2Reader"
        class="org.springframework.batch.item.file.MultiResourceItemReader">
        <property name="resources" value="file:${step2.reader.resource}/*/*/*.xml"></property>
        <property name="delegate" ref="mainReader"></property>
    </bean>

<bean id="mainReader" class="org.springframework.batch.item.xml.StaxEventItemReader"
        scope="step">
        <property name="fragmentRootElementName" value="Domain" />
        <property name="unmarshaller" ref="domainMarshaller" />
    </bean>

    <bean id="domainMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
        <property name="classesToBeBound">
            <list>
                <value>com.example.Domain</value>
            </list>
        </property>
    </bean>

和Domain.java是一个JAXB生成的类,包含如下字段:

and Domain.java is a JAXB generated class containing a field like this:

 @XmlElement(name = "PATH_TO_DOCUMENT", required = true)
 private String pathtodocument;

应该由输入资源填充为字符串。

which is supposed to be filled by the input resource as a string.

我想过要么扩展 StaxEventItemReader 来包含这个功能,要么以某种方式使资源可见域的处理器并填写字段的值,但卡住了。


有什么建议吗?

I've thought of either extending StaxEventItemReader to include this functionality or somehow make visible the resource to the Processor of the domain and fill the value of field there, but got stuck.

Any suggestions?

推荐答案

让你的 com.example.Domain 对象实现 ResourceAware 因此读者将自动注入当前资源进入对象。

Let your com.example.Domain object implements ResourceAware so reader will automagically injects current resource into Domain object.

这篇关于Reader(StaxEventItemReader)Resource to Domain对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆