Spring Batch - MongoDB to XML - Caused by: java.lang.IllegalStateException: A type to convert the input into is required

泄露秘密 提交于 2019-12-02 03:09:57

As the error points out, you need to set the "type" property on your "mongodbItemReader" bean.

See MongoItemReader javadoc.

Example:

<bean id="mongodbItemReader" class="org.springframework.batch.item.data.MongoItemReader">
    <property name="template" ref="mongoTemplate" />
    <property name="collection" value="report" />
    <property name="targetType" value="Report.class" />
</bean>

You might need to specify the package name in the value (I haven't tried it).

Thank you @Sergio, it was great help from you, but below configuration works.

<bean id="mongodbItemReader" class="org.springframework.batch.item.data.MongoItemReader">
        <property name="template" ref="mongoTemplate" />
        <property name="collection" value="report" />
        <property name="targetType" value="com.mkyong.model.Report" />
        <property name="query" value="{'_id':{$gt:0} }" />
        <property name="sort">
            <util:map>
                 <entry key="id" value="#{T(org.springframework.data.domain.Sort.Direction).ASC}" /> 
            </util:map>
        </property>
    </bean>

The only problem I see, nothing is getting write into the XML file. I will raise a separate question for this issue.

Note: The main reason of this error is you need to set <property name="targetType" value="com.mkyong.model.Report" /> this property correctly.

You can also refer: http://www.mkyong.com/spring-batch/how-to-convert-date-in-beanwrapperfieldsetmapper/ as another solution.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!