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

后端 未结 2 1204
醉酒成梦
醉酒成梦 2021-01-24 18:35

I am developing Spring Batch - MongoDB to XML example. In this example, when I run the main method I see the below error is cominng. Please guide on the below error

相关标签:
2条回答
  • 2021-01-24 19:37

    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.

    0 讨论(0)
  • 2021-01-24 19:38

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

    0 讨论(0)
提交回复
热议问题