Spring-batch job randomly throws different exit statuses among FAILED and COMPLETED












0















Here are the configurations of a spring-batch project.



build.gradle:



apply plugin: 'java'

repositories {
jcenter()
mavenCentral()
maven { url "http://repo.spring.io/libs-milestone" }
}

dependencies {

// https://mvnrepository.com/artifact/org.springframework/spring-core
compile group: 'org.springframework', name: 'spring-core', version: '5.1.3.RELEASE'

// https://mvnrepository.com/artifact/org.springframework/spring-context
compile group: 'org.springframework', name: 'spring-context', version: '5.1.3.RELEASE'

// https://mvnrepository.com/artifact/org.springframework/spring-web
compile group: 'org.springframework', name: 'spring-web', version: '5.1.3.RELEASE'

compile group: 'org.springframework', name: 'spring-webmvc', version: '5.1.3.RELEASE'

// https://mvnrepository.com/artifact/org.springframework.batch/spring-batch-core
compile group: 'org.springframework.batch', name: 'spring-batch-core', version: '4.1.0.RELEASE'

// https://mvnrepository.com/artifact/org.springframework.batch/spring-batch-infrastructure
compile group: 'org.springframework.batch', name: 'spring-batch-infrastructure', version: '4.1.0.RELEASE'

// https://mvnrepository.com/artifact/org.springframework.batch/spring-batch-test
testCompile group: 'org.springframework.batch', name: 'spring-batch-test', version: '4.1.0.RELEASE'

// https://mvnrepository.com/artifact/org.springframework.data/spring-data-mongodb
compile group: 'org.springframework.data', name: 'spring-data-mongodb', version: '2.1.3.RELEASE'

compile group: 'org.mongodb', name: 'mongo-java-driver', version: '3.9.1'

compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.6'

// https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.9.7'

}


Job configuration:



<batch:job id="batchUpdateJob" job-repository="jobRepository">
<batch:step id="step1" next="step2">
<batch:tasklet allow-start-if-complete="true">
<batch:chunk reader=“reader1”
writer="compositeWriter" processor=“processor1” commit-interval="10" />
</batch:tasklet>
</batch:step>

<batch:step id="step2">
<batch:tasklet allow-start-if-complete="true">
<batch:chunk reader=“reader2”
writer=“writer2” processor=“processor2” commit-interval="10" />
</batch:tasklet>
</batch:step>
</batch:job>


main() where the batch job is run:



public static void main(String args) {
// Loading The Bean Definition From The Spring Configuration File
contextObj = new ClassPathXmlApplicationContext(springConfig);
jobObj = (Job) contextObj.getBean(JOB_NAME);
jobLauncherObj = (JobLauncher) contextObj.getBean(JOB_LAUNCHER_NAME);
try {
JobParametersBuilder jobBuilder = new JobParametersBuilder();
JobExecution execution = jobLauncherObj.run(jobObj, jobParameters);
System.out.println("Exit Status : " + execution.getStatus());
} catch (Exception exceptionObj) {
exceptionObj.printStackTrace();
}
System.out.println("Done");
}


For each run of the main(), the exitStatus of the job executed is either COMPLETED or FAILED, though no change to the project is made in between the runs.



And when the exit status is FAILED, the stepExecutions has the following trace:




[StepExecution: id=1, version=2, name=step1, status=FAILED, exitStatus=FAILED, readCount=0, filterCount=0, writeCount=0 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=0, rollbackCount=0, exitDescription=org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.reader1’ defined in class path resource [spring/batch/jobs/spring-beans.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.lang.String' to required type 'org.springframework.data.mongodb.core.query.Query' for property 'query'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'org.springframework.data.mongodb.core.query.Query' for property 'query': no matching editors or conversion strategy found
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:584)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$1(AbstractBeanFactory.java:356)
at org.springframework.batch.core.scope.StepScope.get(StepScope.java:113)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:353)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.aop.target.SimpleBeanTargetSource.getTarget(SimpleBeanTargetSource.java:35)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:193)
at com.sun.proxy.$Proxy18.open(Unknown Source)
at org.springframework.batch.item.support.CompositeItemStream.open(CompositeItemStream.java:103)
at org.springframework.batch.core.step.tasklet.TaskletStep.open(TaskletStep.java:311)
at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:200)
at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148)
at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:68)
at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:67)
at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:169)
at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:144)
at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:136)
at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:313)
at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:144)
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50)
at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:137)
at com.simba.tool.cacheserver.batchprocess.App.main(App.java:39)
Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.lang.String' to required type 'org.springframework.data.mongodb.core.query.Query' for property 'query'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'org.springframework.data.mongodb.core.query.Query' for property 'query': no matching editors or conversion strategy found
at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:590)
at org.springframework.beans.AbstractNestablePropertyAccessor.convertForProperty(AbstractNestablePropertyAccessor.java:604)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:219)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1697)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1653)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1400)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:575)
... 22 more
Caused by: java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'org.springframework.data.mongodb.core.query.Query' for property 'query': no matching editors or conversion strategy found
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:299)
at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:585)
... 28 more
]




Bean defining both the readers are configured like this:



    <bean id="reader"
class="org.springframework.batch.item.data.MongoItemReader" scope="step">
<property name="template" ref="mongoTemplate" />
<property name="collection" value="Collection" />
<property name="targetType" value="com.example.SomeObject" />
<property name="query" value="{ $and : [ { 'Field1': /.*#{jobParameters['Param1']}.*/ }, { 'Field2': { $gte: ISODate('9999-12-30T00:00:00Z') } }, { 'Field3': { '$eq': 'Open' } } ] }" />
<property name="sort">
<util:map>
<entry key="Field4" value="#{T(org.springframework.data.domain.Sort.Direction).ASC}" />
</util:map>
</property>
<property name="fields" value="{ 'Field5': 1, 'Field6': 1, 'Field7': 1 }" />
</bean>


Previous research:



My search on the exception message: Cannot convert value of type 'java.lang.String' to required type 'org.springframework.data.mongodb.core.query.Query' for property 'query’ did not fetch any relevant results.
The research using keywords like the ones in the title of this question did not shed much light either.



Why does the execution of the batch job fail sometimes and finish other times? What is the fix for this?





Update:
Tried changing the definition of the readers to this:



<bean id="query" class="java.lang.String">
<constructor-arg value="your json query here"/>
</bean>

<bean id="mongoItemReader" class="org.springframework.batch.item.data.MongoItemReader">
<property name="query" ref="query"/>
<!-- define other properties of the reader here -->
</bean>


Now ended up with the following trace:




[StepExecution: id=1, version=2, name=step1, status=FAILED, exitStatus=FAILED, readCount=0, filterCount=0, writeCount=0 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=0, rollbackCount=0, exitDescription=org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.reader' defined in class path resource [spring/batch/jobs/spring-beans.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'com.sun.proxy.$Proxy19 implementing java.io.Serializable,java.lang.Comparable,java.lang.CharSequence,org.springframework.aop.scope.ScopedObject,org.springframework.aop.framework.AopInfrastructureBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised,org.springframework.core.DecoratingProxy' to required type 'org.springframework.data.mongodb.core.query.Query' for property 'query'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'com.sun.proxy.$Proxy19 implementing java.io.Serializable,java.lang.Comparable,java.lang.CharSequence,org.springframework.aop.scope.ScopedObject,org.springframework.aop.framework.AopInfrastructureBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised,org.springframework.core.DecoratingProxy' to required type 'org.springframework.data.mongodb.core.query.Query' for property 'query': no matching editors or conversion strategy found
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:584)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$1(AbstractBeanFactory.java:356)
at org.springframework.batch.core.scope.StepScope.get(StepScope.java:113)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:353)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.aop.target.SimpleBeanTargetSource.getTarget(SimpleBeanTargetSource.java:35)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:193)
at com.sun.proxy.$Proxy18.open(Unknown Source)
at org.springframework.batch.item.support.CompositeItemStream.open(CompositeItemStream.java:103)
at org.springframework.batch.core.step.tasklet.TaskletStep.open(TaskletStep.java:311)
at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:200)
at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148)
at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:68)
at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:67)
at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:169)
at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:144)
at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:136)
at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:313)
at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:144)
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50)
at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:137)
at com.simba.tool.cacheserver.batchprocess.App.main(App.java:41)
Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'com.sun.proxy.$Proxy19 implementing java.io.Serializable,java.lang.Comparable,java.lang.CharSequence,org.springframework.aop.scope.ScopedObject,org.springframework.aop.framework.AopInfrastructureBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised,org.springframework.core.DecoratingProxy' to required type 'org.springframework.data.mongodb.core.query.Query' for property 'query'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'com.sun.proxy.$Proxy19 implementing java.io.Serializable,java.lang.Comparable,java.lang.CharSequence,org.springframework.aop.scope.ScopedObject,org.springframework.aop.framework.AopInfrastructureBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised,org.springframework.core.DecoratingProxy' to required type 'org.springframework.data.mongodb.core.query.Query' for property 'query': no matching editors or conversion strategy found
at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:590)
at org.springframework.beans.AbstractNestablePropertyAccessor.convertForProperty(AbstractNestablePropertyAccessor.java:604)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:219)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1697)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1653)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1400)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:575)
... 22 more
Caused by: java.lang.IllegalStateException: Cannot convert value of type 'com.sun.proxy.$Proxy19 implementing java.io.Serializable,java.lang.Comparable,java.lang.CharSequence,org.springframework.aop.scope.ScopedObject,org.springframework.aop.framework.AopInfrastructureBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised,org.springframework.core.DecoratingProxy' to required type 'org.springframework.data.mongodb.core.query.Query' for property 'query': no matching editors or conversion strategy found
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:299)
at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:585)
... 28 more
]











share|improve this question




















  • 1





    Can you please share your mongo item reader configuration and tell which Spring Batch version do you use?

    – Mahmoud Ben Hassine
    Jan 2 at 12:36











  • Apologies for forgetting to add the item reader configuration. Edited the question to add that.

    – noob
    Jan 3 at 7:56











  • Thanks for updating the question with the config of the reader. Which Spring Batch version do you use? There was a change made to the MongoItemReader between v3 and v4 and I need to know which version do you use to help you.

    – Mahmoud Ben Hassine
    Jan 3 at 8:13













  • The project uses version 4.1.0.RELEASE of spring-batch-core and version 2.1.3.RELEASE of spring-data-mongodb.

    – noob
    Jan 3 at 9:01








  • 1





    Making the query bean as step scoped is the way to go in order to use late-binding of a a job parameter in the query. Please post the full stacktrace or share a project on github or somewhere else and I will try to help you on it.

    – Mahmoud Ben Hassine
    Jan 9 at 12:10
















0















Here are the configurations of a spring-batch project.



build.gradle:



apply plugin: 'java'

repositories {
jcenter()
mavenCentral()
maven { url "http://repo.spring.io/libs-milestone" }
}

dependencies {

// https://mvnrepository.com/artifact/org.springframework/spring-core
compile group: 'org.springframework', name: 'spring-core', version: '5.1.3.RELEASE'

// https://mvnrepository.com/artifact/org.springframework/spring-context
compile group: 'org.springframework', name: 'spring-context', version: '5.1.3.RELEASE'

// https://mvnrepository.com/artifact/org.springframework/spring-web
compile group: 'org.springframework', name: 'spring-web', version: '5.1.3.RELEASE'

compile group: 'org.springframework', name: 'spring-webmvc', version: '5.1.3.RELEASE'

// https://mvnrepository.com/artifact/org.springframework.batch/spring-batch-core
compile group: 'org.springframework.batch', name: 'spring-batch-core', version: '4.1.0.RELEASE'

// https://mvnrepository.com/artifact/org.springframework.batch/spring-batch-infrastructure
compile group: 'org.springframework.batch', name: 'spring-batch-infrastructure', version: '4.1.0.RELEASE'

// https://mvnrepository.com/artifact/org.springframework.batch/spring-batch-test
testCompile group: 'org.springframework.batch', name: 'spring-batch-test', version: '4.1.0.RELEASE'

// https://mvnrepository.com/artifact/org.springframework.data/spring-data-mongodb
compile group: 'org.springframework.data', name: 'spring-data-mongodb', version: '2.1.3.RELEASE'

compile group: 'org.mongodb', name: 'mongo-java-driver', version: '3.9.1'

compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.6'

// https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.9.7'

}


Job configuration:



<batch:job id="batchUpdateJob" job-repository="jobRepository">
<batch:step id="step1" next="step2">
<batch:tasklet allow-start-if-complete="true">
<batch:chunk reader=“reader1”
writer="compositeWriter" processor=“processor1” commit-interval="10" />
</batch:tasklet>
</batch:step>

<batch:step id="step2">
<batch:tasklet allow-start-if-complete="true">
<batch:chunk reader=“reader2”
writer=“writer2” processor=“processor2” commit-interval="10" />
</batch:tasklet>
</batch:step>
</batch:job>


main() where the batch job is run:



public static void main(String args) {
// Loading The Bean Definition From The Spring Configuration File
contextObj = new ClassPathXmlApplicationContext(springConfig);
jobObj = (Job) contextObj.getBean(JOB_NAME);
jobLauncherObj = (JobLauncher) contextObj.getBean(JOB_LAUNCHER_NAME);
try {
JobParametersBuilder jobBuilder = new JobParametersBuilder();
JobExecution execution = jobLauncherObj.run(jobObj, jobParameters);
System.out.println("Exit Status : " + execution.getStatus());
} catch (Exception exceptionObj) {
exceptionObj.printStackTrace();
}
System.out.println("Done");
}


For each run of the main(), the exitStatus of the job executed is either COMPLETED or FAILED, though no change to the project is made in between the runs.



And when the exit status is FAILED, the stepExecutions has the following trace:




[StepExecution: id=1, version=2, name=step1, status=FAILED, exitStatus=FAILED, readCount=0, filterCount=0, writeCount=0 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=0, rollbackCount=0, exitDescription=org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.reader1’ defined in class path resource [spring/batch/jobs/spring-beans.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.lang.String' to required type 'org.springframework.data.mongodb.core.query.Query' for property 'query'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'org.springframework.data.mongodb.core.query.Query' for property 'query': no matching editors or conversion strategy found
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:584)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$1(AbstractBeanFactory.java:356)
at org.springframework.batch.core.scope.StepScope.get(StepScope.java:113)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:353)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.aop.target.SimpleBeanTargetSource.getTarget(SimpleBeanTargetSource.java:35)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:193)
at com.sun.proxy.$Proxy18.open(Unknown Source)
at org.springframework.batch.item.support.CompositeItemStream.open(CompositeItemStream.java:103)
at org.springframework.batch.core.step.tasklet.TaskletStep.open(TaskletStep.java:311)
at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:200)
at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148)
at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:68)
at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:67)
at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:169)
at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:144)
at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:136)
at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:313)
at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:144)
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50)
at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:137)
at com.simba.tool.cacheserver.batchprocess.App.main(App.java:39)
Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.lang.String' to required type 'org.springframework.data.mongodb.core.query.Query' for property 'query'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'org.springframework.data.mongodb.core.query.Query' for property 'query': no matching editors or conversion strategy found
at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:590)
at org.springframework.beans.AbstractNestablePropertyAccessor.convertForProperty(AbstractNestablePropertyAccessor.java:604)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:219)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1697)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1653)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1400)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:575)
... 22 more
Caused by: java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'org.springframework.data.mongodb.core.query.Query' for property 'query': no matching editors or conversion strategy found
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:299)
at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:585)
... 28 more
]




Bean defining both the readers are configured like this:



    <bean id="reader"
class="org.springframework.batch.item.data.MongoItemReader" scope="step">
<property name="template" ref="mongoTemplate" />
<property name="collection" value="Collection" />
<property name="targetType" value="com.example.SomeObject" />
<property name="query" value="{ $and : [ { 'Field1': /.*#{jobParameters['Param1']}.*/ }, { 'Field2': { $gte: ISODate('9999-12-30T00:00:00Z') } }, { 'Field3': { '$eq': 'Open' } } ] }" />
<property name="sort">
<util:map>
<entry key="Field4" value="#{T(org.springframework.data.domain.Sort.Direction).ASC}" />
</util:map>
</property>
<property name="fields" value="{ 'Field5': 1, 'Field6': 1, 'Field7': 1 }" />
</bean>


Previous research:



My search on the exception message: Cannot convert value of type 'java.lang.String' to required type 'org.springframework.data.mongodb.core.query.Query' for property 'query’ did not fetch any relevant results.
The research using keywords like the ones in the title of this question did not shed much light either.



Why does the execution of the batch job fail sometimes and finish other times? What is the fix for this?





Update:
Tried changing the definition of the readers to this:



<bean id="query" class="java.lang.String">
<constructor-arg value="your json query here"/>
</bean>

<bean id="mongoItemReader" class="org.springframework.batch.item.data.MongoItemReader">
<property name="query" ref="query"/>
<!-- define other properties of the reader here -->
</bean>


Now ended up with the following trace:




[StepExecution: id=1, version=2, name=step1, status=FAILED, exitStatus=FAILED, readCount=0, filterCount=0, writeCount=0 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=0, rollbackCount=0, exitDescription=org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.reader' defined in class path resource [spring/batch/jobs/spring-beans.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'com.sun.proxy.$Proxy19 implementing java.io.Serializable,java.lang.Comparable,java.lang.CharSequence,org.springframework.aop.scope.ScopedObject,org.springframework.aop.framework.AopInfrastructureBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised,org.springframework.core.DecoratingProxy' to required type 'org.springframework.data.mongodb.core.query.Query' for property 'query'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'com.sun.proxy.$Proxy19 implementing java.io.Serializable,java.lang.Comparable,java.lang.CharSequence,org.springframework.aop.scope.ScopedObject,org.springframework.aop.framework.AopInfrastructureBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised,org.springframework.core.DecoratingProxy' to required type 'org.springframework.data.mongodb.core.query.Query' for property 'query': no matching editors or conversion strategy found
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:584)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$1(AbstractBeanFactory.java:356)
at org.springframework.batch.core.scope.StepScope.get(StepScope.java:113)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:353)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.aop.target.SimpleBeanTargetSource.getTarget(SimpleBeanTargetSource.java:35)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:193)
at com.sun.proxy.$Proxy18.open(Unknown Source)
at org.springframework.batch.item.support.CompositeItemStream.open(CompositeItemStream.java:103)
at org.springframework.batch.core.step.tasklet.TaskletStep.open(TaskletStep.java:311)
at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:200)
at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148)
at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:68)
at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:67)
at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:169)
at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:144)
at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:136)
at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:313)
at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:144)
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50)
at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:137)
at com.simba.tool.cacheserver.batchprocess.App.main(App.java:41)
Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'com.sun.proxy.$Proxy19 implementing java.io.Serializable,java.lang.Comparable,java.lang.CharSequence,org.springframework.aop.scope.ScopedObject,org.springframework.aop.framework.AopInfrastructureBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised,org.springframework.core.DecoratingProxy' to required type 'org.springframework.data.mongodb.core.query.Query' for property 'query'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'com.sun.proxy.$Proxy19 implementing java.io.Serializable,java.lang.Comparable,java.lang.CharSequence,org.springframework.aop.scope.ScopedObject,org.springframework.aop.framework.AopInfrastructureBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised,org.springframework.core.DecoratingProxy' to required type 'org.springframework.data.mongodb.core.query.Query' for property 'query': no matching editors or conversion strategy found
at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:590)
at org.springframework.beans.AbstractNestablePropertyAccessor.convertForProperty(AbstractNestablePropertyAccessor.java:604)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:219)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1697)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1653)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1400)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:575)
... 22 more
Caused by: java.lang.IllegalStateException: Cannot convert value of type 'com.sun.proxy.$Proxy19 implementing java.io.Serializable,java.lang.Comparable,java.lang.CharSequence,org.springframework.aop.scope.ScopedObject,org.springframework.aop.framework.AopInfrastructureBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised,org.springframework.core.DecoratingProxy' to required type 'org.springframework.data.mongodb.core.query.Query' for property 'query': no matching editors or conversion strategy found
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:299)
at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:585)
... 28 more
]











share|improve this question




















  • 1





    Can you please share your mongo item reader configuration and tell which Spring Batch version do you use?

    – Mahmoud Ben Hassine
    Jan 2 at 12:36











  • Apologies for forgetting to add the item reader configuration. Edited the question to add that.

    – noob
    Jan 3 at 7:56











  • Thanks for updating the question with the config of the reader. Which Spring Batch version do you use? There was a change made to the MongoItemReader between v3 and v4 and I need to know which version do you use to help you.

    – Mahmoud Ben Hassine
    Jan 3 at 8:13













  • The project uses version 4.1.0.RELEASE of spring-batch-core and version 2.1.3.RELEASE of spring-data-mongodb.

    – noob
    Jan 3 at 9:01








  • 1





    Making the query bean as step scoped is the way to go in order to use late-binding of a a job parameter in the query. Please post the full stacktrace or share a project on github or somewhere else and I will try to help you on it.

    – Mahmoud Ben Hassine
    Jan 9 at 12:10














0












0








0








Here are the configurations of a spring-batch project.



build.gradle:



apply plugin: 'java'

repositories {
jcenter()
mavenCentral()
maven { url "http://repo.spring.io/libs-milestone" }
}

dependencies {

// https://mvnrepository.com/artifact/org.springframework/spring-core
compile group: 'org.springframework', name: 'spring-core', version: '5.1.3.RELEASE'

// https://mvnrepository.com/artifact/org.springframework/spring-context
compile group: 'org.springframework', name: 'spring-context', version: '5.1.3.RELEASE'

// https://mvnrepository.com/artifact/org.springframework/spring-web
compile group: 'org.springframework', name: 'spring-web', version: '5.1.3.RELEASE'

compile group: 'org.springframework', name: 'spring-webmvc', version: '5.1.3.RELEASE'

// https://mvnrepository.com/artifact/org.springframework.batch/spring-batch-core
compile group: 'org.springframework.batch', name: 'spring-batch-core', version: '4.1.0.RELEASE'

// https://mvnrepository.com/artifact/org.springframework.batch/spring-batch-infrastructure
compile group: 'org.springframework.batch', name: 'spring-batch-infrastructure', version: '4.1.0.RELEASE'

// https://mvnrepository.com/artifact/org.springframework.batch/spring-batch-test
testCompile group: 'org.springframework.batch', name: 'spring-batch-test', version: '4.1.0.RELEASE'

// https://mvnrepository.com/artifact/org.springframework.data/spring-data-mongodb
compile group: 'org.springframework.data', name: 'spring-data-mongodb', version: '2.1.3.RELEASE'

compile group: 'org.mongodb', name: 'mongo-java-driver', version: '3.9.1'

compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.6'

// https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.9.7'

}


Job configuration:



<batch:job id="batchUpdateJob" job-repository="jobRepository">
<batch:step id="step1" next="step2">
<batch:tasklet allow-start-if-complete="true">
<batch:chunk reader=“reader1”
writer="compositeWriter" processor=“processor1” commit-interval="10" />
</batch:tasklet>
</batch:step>

<batch:step id="step2">
<batch:tasklet allow-start-if-complete="true">
<batch:chunk reader=“reader2”
writer=“writer2” processor=“processor2” commit-interval="10" />
</batch:tasklet>
</batch:step>
</batch:job>


main() where the batch job is run:



public static void main(String args) {
// Loading The Bean Definition From The Spring Configuration File
contextObj = new ClassPathXmlApplicationContext(springConfig);
jobObj = (Job) contextObj.getBean(JOB_NAME);
jobLauncherObj = (JobLauncher) contextObj.getBean(JOB_LAUNCHER_NAME);
try {
JobParametersBuilder jobBuilder = new JobParametersBuilder();
JobExecution execution = jobLauncherObj.run(jobObj, jobParameters);
System.out.println("Exit Status : " + execution.getStatus());
} catch (Exception exceptionObj) {
exceptionObj.printStackTrace();
}
System.out.println("Done");
}


For each run of the main(), the exitStatus of the job executed is either COMPLETED or FAILED, though no change to the project is made in between the runs.



And when the exit status is FAILED, the stepExecutions has the following trace:




[StepExecution: id=1, version=2, name=step1, status=FAILED, exitStatus=FAILED, readCount=0, filterCount=0, writeCount=0 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=0, rollbackCount=0, exitDescription=org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.reader1’ defined in class path resource [spring/batch/jobs/spring-beans.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.lang.String' to required type 'org.springframework.data.mongodb.core.query.Query' for property 'query'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'org.springframework.data.mongodb.core.query.Query' for property 'query': no matching editors or conversion strategy found
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:584)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$1(AbstractBeanFactory.java:356)
at org.springframework.batch.core.scope.StepScope.get(StepScope.java:113)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:353)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.aop.target.SimpleBeanTargetSource.getTarget(SimpleBeanTargetSource.java:35)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:193)
at com.sun.proxy.$Proxy18.open(Unknown Source)
at org.springframework.batch.item.support.CompositeItemStream.open(CompositeItemStream.java:103)
at org.springframework.batch.core.step.tasklet.TaskletStep.open(TaskletStep.java:311)
at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:200)
at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148)
at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:68)
at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:67)
at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:169)
at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:144)
at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:136)
at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:313)
at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:144)
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50)
at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:137)
at com.simba.tool.cacheserver.batchprocess.App.main(App.java:39)
Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.lang.String' to required type 'org.springframework.data.mongodb.core.query.Query' for property 'query'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'org.springframework.data.mongodb.core.query.Query' for property 'query': no matching editors or conversion strategy found
at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:590)
at org.springframework.beans.AbstractNestablePropertyAccessor.convertForProperty(AbstractNestablePropertyAccessor.java:604)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:219)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1697)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1653)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1400)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:575)
... 22 more
Caused by: java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'org.springframework.data.mongodb.core.query.Query' for property 'query': no matching editors or conversion strategy found
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:299)
at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:585)
... 28 more
]




Bean defining both the readers are configured like this:



    <bean id="reader"
class="org.springframework.batch.item.data.MongoItemReader" scope="step">
<property name="template" ref="mongoTemplate" />
<property name="collection" value="Collection" />
<property name="targetType" value="com.example.SomeObject" />
<property name="query" value="{ $and : [ { 'Field1': /.*#{jobParameters['Param1']}.*/ }, { 'Field2': { $gte: ISODate('9999-12-30T00:00:00Z') } }, { 'Field3': { '$eq': 'Open' } } ] }" />
<property name="sort">
<util:map>
<entry key="Field4" value="#{T(org.springframework.data.domain.Sort.Direction).ASC}" />
</util:map>
</property>
<property name="fields" value="{ 'Field5': 1, 'Field6': 1, 'Field7': 1 }" />
</bean>


Previous research:



My search on the exception message: Cannot convert value of type 'java.lang.String' to required type 'org.springframework.data.mongodb.core.query.Query' for property 'query’ did not fetch any relevant results.
The research using keywords like the ones in the title of this question did not shed much light either.



Why does the execution of the batch job fail sometimes and finish other times? What is the fix for this?





Update:
Tried changing the definition of the readers to this:



<bean id="query" class="java.lang.String">
<constructor-arg value="your json query here"/>
</bean>

<bean id="mongoItemReader" class="org.springframework.batch.item.data.MongoItemReader">
<property name="query" ref="query"/>
<!-- define other properties of the reader here -->
</bean>


Now ended up with the following trace:




[StepExecution: id=1, version=2, name=step1, status=FAILED, exitStatus=FAILED, readCount=0, filterCount=0, writeCount=0 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=0, rollbackCount=0, exitDescription=org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.reader' defined in class path resource [spring/batch/jobs/spring-beans.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'com.sun.proxy.$Proxy19 implementing java.io.Serializable,java.lang.Comparable,java.lang.CharSequence,org.springframework.aop.scope.ScopedObject,org.springframework.aop.framework.AopInfrastructureBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised,org.springframework.core.DecoratingProxy' to required type 'org.springframework.data.mongodb.core.query.Query' for property 'query'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'com.sun.proxy.$Proxy19 implementing java.io.Serializable,java.lang.Comparable,java.lang.CharSequence,org.springframework.aop.scope.ScopedObject,org.springframework.aop.framework.AopInfrastructureBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised,org.springframework.core.DecoratingProxy' to required type 'org.springframework.data.mongodb.core.query.Query' for property 'query': no matching editors or conversion strategy found
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:584)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$1(AbstractBeanFactory.java:356)
at org.springframework.batch.core.scope.StepScope.get(StepScope.java:113)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:353)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.aop.target.SimpleBeanTargetSource.getTarget(SimpleBeanTargetSource.java:35)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:193)
at com.sun.proxy.$Proxy18.open(Unknown Source)
at org.springframework.batch.item.support.CompositeItemStream.open(CompositeItemStream.java:103)
at org.springframework.batch.core.step.tasklet.TaskletStep.open(TaskletStep.java:311)
at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:200)
at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148)
at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:68)
at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:67)
at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:169)
at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:144)
at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:136)
at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:313)
at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:144)
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50)
at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:137)
at com.simba.tool.cacheserver.batchprocess.App.main(App.java:41)
Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'com.sun.proxy.$Proxy19 implementing java.io.Serializable,java.lang.Comparable,java.lang.CharSequence,org.springframework.aop.scope.ScopedObject,org.springframework.aop.framework.AopInfrastructureBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised,org.springframework.core.DecoratingProxy' to required type 'org.springframework.data.mongodb.core.query.Query' for property 'query'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'com.sun.proxy.$Proxy19 implementing java.io.Serializable,java.lang.Comparable,java.lang.CharSequence,org.springframework.aop.scope.ScopedObject,org.springframework.aop.framework.AopInfrastructureBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised,org.springframework.core.DecoratingProxy' to required type 'org.springframework.data.mongodb.core.query.Query' for property 'query': no matching editors or conversion strategy found
at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:590)
at org.springframework.beans.AbstractNestablePropertyAccessor.convertForProperty(AbstractNestablePropertyAccessor.java:604)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:219)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1697)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1653)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1400)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:575)
... 22 more
Caused by: java.lang.IllegalStateException: Cannot convert value of type 'com.sun.proxy.$Proxy19 implementing java.io.Serializable,java.lang.Comparable,java.lang.CharSequence,org.springframework.aop.scope.ScopedObject,org.springframework.aop.framework.AopInfrastructureBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised,org.springframework.core.DecoratingProxy' to required type 'org.springframework.data.mongodb.core.query.Query' for property 'query': no matching editors or conversion strategy found
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:299)
at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:585)
... 28 more
]











share|improve this question
















Here are the configurations of a spring-batch project.



build.gradle:



apply plugin: 'java'

repositories {
jcenter()
mavenCentral()
maven { url "http://repo.spring.io/libs-milestone" }
}

dependencies {

// https://mvnrepository.com/artifact/org.springframework/spring-core
compile group: 'org.springframework', name: 'spring-core', version: '5.1.3.RELEASE'

// https://mvnrepository.com/artifact/org.springframework/spring-context
compile group: 'org.springframework', name: 'spring-context', version: '5.1.3.RELEASE'

// https://mvnrepository.com/artifact/org.springframework/spring-web
compile group: 'org.springframework', name: 'spring-web', version: '5.1.3.RELEASE'

compile group: 'org.springframework', name: 'spring-webmvc', version: '5.1.3.RELEASE'

// https://mvnrepository.com/artifact/org.springframework.batch/spring-batch-core
compile group: 'org.springframework.batch', name: 'spring-batch-core', version: '4.1.0.RELEASE'

// https://mvnrepository.com/artifact/org.springframework.batch/spring-batch-infrastructure
compile group: 'org.springframework.batch', name: 'spring-batch-infrastructure', version: '4.1.0.RELEASE'

// https://mvnrepository.com/artifact/org.springframework.batch/spring-batch-test
testCompile group: 'org.springframework.batch', name: 'spring-batch-test', version: '4.1.0.RELEASE'

// https://mvnrepository.com/artifact/org.springframework.data/spring-data-mongodb
compile group: 'org.springframework.data', name: 'spring-data-mongodb', version: '2.1.3.RELEASE'

compile group: 'org.mongodb', name: 'mongo-java-driver', version: '3.9.1'

compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.6'

// https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.9.7'

}


Job configuration:



<batch:job id="batchUpdateJob" job-repository="jobRepository">
<batch:step id="step1" next="step2">
<batch:tasklet allow-start-if-complete="true">
<batch:chunk reader=“reader1”
writer="compositeWriter" processor=“processor1” commit-interval="10" />
</batch:tasklet>
</batch:step>

<batch:step id="step2">
<batch:tasklet allow-start-if-complete="true">
<batch:chunk reader=“reader2”
writer=“writer2” processor=“processor2” commit-interval="10" />
</batch:tasklet>
</batch:step>
</batch:job>


main() where the batch job is run:



public static void main(String args) {
// Loading The Bean Definition From The Spring Configuration File
contextObj = new ClassPathXmlApplicationContext(springConfig);
jobObj = (Job) contextObj.getBean(JOB_NAME);
jobLauncherObj = (JobLauncher) contextObj.getBean(JOB_LAUNCHER_NAME);
try {
JobParametersBuilder jobBuilder = new JobParametersBuilder();
JobExecution execution = jobLauncherObj.run(jobObj, jobParameters);
System.out.println("Exit Status : " + execution.getStatus());
} catch (Exception exceptionObj) {
exceptionObj.printStackTrace();
}
System.out.println("Done");
}


For each run of the main(), the exitStatus of the job executed is either COMPLETED or FAILED, though no change to the project is made in between the runs.



And when the exit status is FAILED, the stepExecutions has the following trace:




[StepExecution: id=1, version=2, name=step1, status=FAILED, exitStatus=FAILED, readCount=0, filterCount=0, writeCount=0 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=0, rollbackCount=0, exitDescription=org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.reader1’ defined in class path resource [spring/batch/jobs/spring-beans.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.lang.String' to required type 'org.springframework.data.mongodb.core.query.Query' for property 'query'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'org.springframework.data.mongodb.core.query.Query' for property 'query': no matching editors or conversion strategy found
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:584)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$1(AbstractBeanFactory.java:356)
at org.springframework.batch.core.scope.StepScope.get(StepScope.java:113)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:353)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.aop.target.SimpleBeanTargetSource.getTarget(SimpleBeanTargetSource.java:35)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:193)
at com.sun.proxy.$Proxy18.open(Unknown Source)
at org.springframework.batch.item.support.CompositeItemStream.open(CompositeItemStream.java:103)
at org.springframework.batch.core.step.tasklet.TaskletStep.open(TaskletStep.java:311)
at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:200)
at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148)
at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:68)
at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:67)
at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:169)
at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:144)
at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:136)
at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:313)
at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:144)
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50)
at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:137)
at com.simba.tool.cacheserver.batchprocess.App.main(App.java:39)
Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.lang.String' to required type 'org.springframework.data.mongodb.core.query.Query' for property 'query'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'org.springframework.data.mongodb.core.query.Query' for property 'query': no matching editors or conversion strategy found
at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:590)
at org.springframework.beans.AbstractNestablePropertyAccessor.convertForProperty(AbstractNestablePropertyAccessor.java:604)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:219)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1697)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1653)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1400)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:575)
... 22 more
Caused by: java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'org.springframework.data.mongodb.core.query.Query' for property 'query': no matching editors or conversion strategy found
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:299)
at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:585)
... 28 more
]




Bean defining both the readers are configured like this:



    <bean id="reader"
class="org.springframework.batch.item.data.MongoItemReader" scope="step">
<property name="template" ref="mongoTemplate" />
<property name="collection" value="Collection" />
<property name="targetType" value="com.example.SomeObject" />
<property name="query" value="{ $and : [ { 'Field1': /.*#{jobParameters['Param1']}.*/ }, { 'Field2': { $gte: ISODate('9999-12-30T00:00:00Z') } }, { 'Field3': { '$eq': 'Open' } } ] }" />
<property name="sort">
<util:map>
<entry key="Field4" value="#{T(org.springframework.data.domain.Sort.Direction).ASC}" />
</util:map>
</property>
<property name="fields" value="{ 'Field5': 1, 'Field6': 1, 'Field7': 1 }" />
</bean>


Previous research:



My search on the exception message: Cannot convert value of type 'java.lang.String' to required type 'org.springframework.data.mongodb.core.query.Query' for property 'query’ did not fetch any relevant results.
The research using keywords like the ones in the title of this question did not shed much light either.



Why does the execution of the batch job fail sometimes and finish other times? What is the fix for this?





Update:
Tried changing the definition of the readers to this:



<bean id="query" class="java.lang.String">
<constructor-arg value="your json query here"/>
</bean>

<bean id="mongoItemReader" class="org.springframework.batch.item.data.MongoItemReader">
<property name="query" ref="query"/>
<!-- define other properties of the reader here -->
</bean>


Now ended up with the following trace:




[StepExecution: id=1, version=2, name=step1, status=FAILED, exitStatus=FAILED, readCount=0, filterCount=0, writeCount=0 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=0, rollbackCount=0, exitDescription=org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.reader' defined in class path resource [spring/batch/jobs/spring-beans.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'com.sun.proxy.$Proxy19 implementing java.io.Serializable,java.lang.Comparable,java.lang.CharSequence,org.springframework.aop.scope.ScopedObject,org.springframework.aop.framework.AopInfrastructureBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised,org.springframework.core.DecoratingProxy' to required type 'org.springframework.data.mongodb.core.query.Query' for property 'query'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'com.sun.proxy.$Proxy19 implementing java.io.Serializable,java.lang.Comparable,java.lang.CharSequence,org.springframework.aop.scope.ScopedObject,org.springframework.aop.framework.AopInfrastructureBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised,org.springframework.core.DecoratingProxy' to required type 'org.springframework.data.mongodb.core.query.Query' for property 'query': no matching editors or conversion strategy found
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:584)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$1(AbstractBeanFactory.java:356)
at org.springframework.batch.core.scope.StepScope.get(StepScope.java:113)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:353)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.aop.target.SimpleBeanTargetSource.getTarget(SimpleBeanTargetSource.java:35)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:193)
at com.sun.proxy.$Proxy18.open(Unknown Source)
at org.springframework.batch.item.support.CompositeItemStream.open(CompositeItemStream.java:103)
at org.springframework.batch.core.step.tasklet.TaskletStep.open(TaskletStep.java:311)
at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:200)
at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148)
at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:68)
at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:67)
at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:169)
at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:144)
at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:136)
at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:313)
at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:144)
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50)
at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:137)
at com.simba.tool.cacheserver.batchprocess.App.main(App.java:41)
Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'com.sun.proxy.$Proxy19 implementing java.io.Serializable,java.lang.Comparable,java.lang.CharSequence,org.springframework.aop.scope.ScopedObject,org.springframework.aop.framework.AopInfrastructureBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised,org.springframework.core.DecoratingProxy' to required type 'org.springframework.data.mongodb.core.query.Query' for property 'query'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'com.sun.proxy.$Proxy19 implementing java.io.Serializable,java.lang.Comparable,java.lang.CharSequence,org.springframework.aop.scope.ScopedObject,org.springframework.aop.framework.AopInfrastructureBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised,org.springframework.core.DecoratingProxy' to required type 'org.springframework.data.mongodb.core.query.Query' for property 'query': no matching editors or conversion strategy found
at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:590)
at org.springframework.beans.AbstractNestablePropertyAccessor.convertForProperty(AbstractNestablePropertyAccessor.java:604)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:219)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1697)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1653)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1400)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:575)
... 22 more
Caused by: java.lang.IllegalStateException: Cannot convert value of type 'com.sun.proxy.$Proxy19 implementing java.io.Serializable,java.lang.Comparable,java.lang.CharSequence,org.springframework.aop.scope.ScopedObject,org.springframework.aop.framework.AopInfrastructureBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised,org.springframework.core.DecoratingProxy' to required type 'org.springframework.data.mongodb.core.query.Query' for property 'query': no matching editors or conversion strategy found
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:299)
at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:585)
... 28 more
]








java spring spring-batch






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 18 at 6:19







noob

















asked Dec 24 '18 at 11:36









noobnoob

5081617




5081617








  • 1





    Can you please share your mongo item reader configuration and tell which Spring Batch version do you use?

    – Mahmoud Ben Hassine
    Jan 2 at 12:36











  • Apologies for forgetting to add the item reader configuration. Edited the question to add that.

    – noob
    Jan 3 at 7:56











  • Thanks for updating the question with the config of the reader. Which Spring Batch version do you use? There was a change made to the MongoItemReader between v3 and v4 and I need to know which version do you use to help you.

    – Mahmoud Ben Hassine
    Jan 3 at 8:13













  • The project uses version 4.1.0.RELEASE of spring-batch-core and version 2.1.3.RELEASE of spring-data-mongodb.

    – noob
    Jan 3 at 9:01








  • 1





    Making the query bean as step scoped is the way to go in order to use late-binding of a a job parameter in the query. Please post the full stacktrace or share a project on github or somewhere else and I will try to help you on it.

    – Mahmoud Ben Hassine
    Jan 9 at 12:10














  • 1





    Can you please share your mongo item reader configuration and tell which Spring Batch version do you use?

    – Mahmoud Ben Hassine
    Jan 2 at 12:36











  • Apologies for forgetting to add the item reader configuration. Edited the question to add that.

    – noob
    Jan 3 at 7:56











  • Thanks for updating the question with the config of the reader. Which Spring Batch version do you use? There was a change made to the MongoItemReader between v3 and v4 and I need to know which version do you use to help you.

    – Mahmoud Ben Hassine
    Jan 3 at 8:13













  • The project uses version 4.1.0.RELEASE of spring-batch-core and version 2.1.3.RELEASE of spring-data-mongodb.

    – noob
    Jan 3 at 9:01








  • 1





    Making the query bean as step scoped is the way to go in order to use late-binding of a a job parameter in the query. Please post the full stacktrace or share a project on github or somewhere else and I will try to help you on it.

    – Mahmoud Ben Hassine
    Jan 9 at 12:10








1




1





Can you please share your mongo item reader configuration and tell which Spring Batch version do you use?

– Mahmoud Ben Hassine
Jan 2 at 12:36





Can you please share your mongo item reader configuration and tell which Spring Batch version do you use?

– Mahmoud Ben Hassine
Jan 2 at 12:36













Apologies for forgetting to add the item reader configuration. Edited the question to add that.

– noob
Jan 3 at 7:56





Apologies for forgetting to add the item reader configuration. Edited the question to add that.

– noob
Jan 3 at 7:56













Thanks for updating the question with the config of the reader. Which Spring Batch version do you use? There was a change made to the MongoItemReader between v3 and v4 and I need to know which version do you use to help you.

– Mahmoud Ben Hassine
Jan 3 at 8:13







Thanks for updating the question with the config of the reader. Which Spring Batch version do you use? There was a change made to the MongoItemReader between v3 and v4 and I need to know which version do you use to help you.

– Mahmoud Ben Hassine
Jan 3 at 8:13















The project uses version 4.1.0.RELEASE of spring-batch-core and version 2.1.3.RELEASE of spring-data-mongodb.

– noob
Jan 3 at 9:01







The project uses version 4.1.0.RELEASE of spring-batch-core and version 2.1.3.RELEASE of spring-data-mongodb.

– noob
Jan 3 at 9:01






1




1





Making the query bean as step scoped is the way to go in order to use late-binding of a a job parameter in the query. Please post the full stacktrace or share a project on github or somewhere else and I will try to help you on it.

– Mahmoud Ben Hassine
Jan 9 at 12:10





Making the query bean as step scoped is the way to go in order to use late-binding of a a job parameter in the query. Please post the full stacktrace or share a project on github or somewhere else and I will try to help you on it.

– Mahmoud Ben Hassine
Jan 9 at 12:10












1 Answer
1






active

oldest

votes


















0














There are two setQuery methods in MongoItemReader: setQuery(Query) and setQuery(String). So when configured with XML, there might be an ambiguity on which one to use. In your case, it looks like Spring is trying to convert your String query into a org.springframework.data.mongodb.core.query.Query object and it does not find a converter for that.



You need to specify which type of query to use and set it on the reader.



In your example, you need to configure the query and the reader with something like:



<bean id="query" class="java.lang.String">
<constructor-arg value="your json query here"/>
</bean>

<bean id="mongoItemReader" class="org.springframework.batch.item.data.MongoItemReader">
<property name="query" ref="query"/>
<!-- define other properties of the reader here -->
</bean>


Hope this helps.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53912923%2fspring-batch-job-randomly-throws-different-exit-statuses-among-failed-and-comple%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    There are two setQuery methods in MongoItemReader: setQuery(Query) and setQuery(String). So when configured with XML, there might be an ambiguity on which one to use. In your case, it looks like Spring is trying to convert your String query into a org.springframework.data.mongodb.core.query.Query object and it does not find a converter for that.



    You need to specify which type of query to use and set it on the reader.



    In your example, you need to configure the query and the reader with something like:



    <bean id="query" class="java.lang.String">
    <constructor-arg value="your json query here"/>
    </bean>

    <bean id="mongoItemReader" class="org.springframework.batch.item.data.MongoItemReader">
    <property name="query" ref="query"/>
    <!-- define other properties of the reader here -->
    </bean>


    Hope this helps.






    share|improve this answer




























      0














      There are two setQuery methods in MongoItemReader: setQuery(Query) and setQuery(String). So when configured with XML, there might be an ambiguity on which one to use. In your case, it looks like Spring is trying to convert your String query into a org.springframework.data.mongodb.core.query.Query object and it does not find a converter for that.



      You need to specify which type of query to use and set it on the reader.



      In your example, you need to configure the query and the reader with something like:



      <bean id="query" class="java.lang.String">
      <constructor-arg value="your json query here"/>
      </bean>

      <bean id="mongoItemReader" class="org.springframework.batch.item.data.MongoItemReader">
      <property name="query" ref="query"/>
      <!-- define other properties of the reader here -->
      </bean>


      Hope this helps.






      share|improve this answer


























        0












        0








        0







        There are two setQuery methods in MongoItemReader: setQuery(Query) and setQuery(String). So when configured with XML, there might be an ambiguity on which one to use. In your case, it looks like Spring is trying to convert your String query into a org.springframework.data.mongodb.core.query.Query object and it does not find a converter for that.



        You need to specify which type of query to use and set it on the reader.



        In your example, you need to configure the query and the reader with something like:



        <bean id="query" class="java.lang.String">
        <constructor-arg value="your json query here"/>
        </bean>

        <bean id="mongoItemReader" class="org.springframework.batch.item.data.MongoItemReader">
        <property name="query" ref="query"/>
        <!-- define other properties of the reader here -->
        </bean>


        Hope this helps.






        share|improve this answer













        There are two setQuery methods in MongoItemReader: setQuery(Query) and setQuery(String). So when configured with XML, there might be an ambiguity on which one to use. In your case, it looks like Spring is trying to convert your String query into a org.springframework.data.mongodb.core.query.Query object and it does not find a converter for that.



        You need to specify which type of query to use and set it on the reader.



        In your example, you need to configure the query and the reader with something like:



        <bean id="query" class="java.lang.String">
        <constructor-arg value="your json query here"/>
        </bean>

        <bean id="mongoItemReader" class="org.springframework.batch.item.data.MongoItemReader">
        <property name="query" ref="query"/>
        <!-- define other properties of the reader here -->
        </bean>


        Hope this helps.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 2 at 12:45









        Mahmoud Ben HassineMahmoud Ben Hassine

        5,3201717




        5,3201717
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53912923%2fspring-batch-job-randomly-throws-different-exit-statuses-among-failed-and-comple%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Monofisismo

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas