2

I'm using spring boot version 1.4.2.RELEASE and sprig batch framework. I'm trying to import data from files and after that storing results in a database, I'm dealing with a dynamic commit interval number so I implemented a method that returns the number of lines of my input file and passing it as a parameter using "jobParameters":

My batch job configuration looks like this:

<beans:bean id="stepScope" class="org.springframework.batch.core.scope.StepScope">
    <beans:property name="autoProxy" value="true"/>
</beans:bean>

<beans:bean id="MyProcessor" class="org.job.step.MyProcessor" scope="step" />
<beans:bean id="MyWriter" class="org.job.step.MyWriter" scope="step" />
<beans:bean id="jobCompleteNotificationListener" class="org.job.JobCompletionNotificationListener" />


<job id="MyImportJob">
    <step id="step1">
        <tasklet transaction-manager="transactionManager">
            <chunk  reader="MyReader" 
                    processor="MyProcessor"
                    writer="MyWriter"
                    commit-interval="#{jobParameters['commit.interval']}" >
            </chunk>    
        </tasklet>
    </step>

    <listeners>
        <listener ref="jobCompleteNotificationListener" />
    </listeners>

</job>


<beans:bean id="headerBasedDelimitedLineTokenizer" scope="step" 
    class="org.job.custom.HeaderBasedDelimitedLineTokenizer">
    <beans:property name="delimiter" value=";" />
</beans:bean>

<!-- <beans:bean id="customLineTokenizer" class="org.job.step.CustomLineTokenizer"/> -->

<beans:bean id="MyReader" scope="step"
    class="org.springframework.batch.item.file.FlatFileItemReader">
    <beans:property name="resource" value="file:/#{jobParameters['input.file.name']}" />
    <beans:property name="encoding" value="UTF-8" />
    <beans:property name="strict" value="false" />
    <beans:property name="linesToSkip" value="1" />
    <beans:property name="skippedLinesCallback">
        <beans:ref bean="headerBasedDelimitedLineTokenizer" />
    </beans:property>
    <beans:property name="lineMapper">
        <beans:bean
            class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
            <beans:property name="lineTokenizer">
                <beans:ref bean="headerBasedDelimitedLineTokenizer" />
            </beans:property>
            <beans:property name="fieldSetMapper">
                <beans:bean class="org.job.step.MyFieldSetMapper" />
            </beans:property>
        </beans:bean>
    </beans:property>
</beans:bean>

It throws an exception as given bellow when first running the spring boot application:

2017-04-07 15:03:04.537 -ERROR [PID=8692] org.springframework.batch.core.step.AbstractStep.execute : Encountered an error executing step step1 in job MyImportJob
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'scopedTarget.org.springframework.batch.repeat.policy.SimpleCompletionPolicy#0': Unsatisfied dependency expressed through constructor parameter 0: Could not convert argument value of type [null] to required type [int]: Failed to convert value of type 'null' to required type 'int'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type 'null' to required type 'int': PropertyEditor [org.springframework.beans.propertyeditors.CustomNumberEditor] returned inappropriate value of type 'null'
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:723)
    at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:189)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1148)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1050)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:512)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$2.getObject(AbstractBeanFactory.java:345)
    at org.springframework.batch.core.scope.StepScope.get(StepScope.java:113)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:340)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.aop.target.SimpleBeanTargetSource.getTarget(SimpleBeanTargetSource.java:35)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:192)
    at com.sun.proxy.$Proxy50.start(Unknown Source)
    at org.springframework.batch.repeat.support.RepeatTemplate.start(RepeatTemplate.java:468)
    at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:169)
    at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:144)
    at org.springframework.batch.core.step.item.SimpleChunkProvider.provide(SimpleChunkProvider.java:110)
    at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:69)
    at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:406)
    at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:330)
    at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133)
    at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:271)
    at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:81)
    at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:374)
    at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215)
    at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:144)
    at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:257)
    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:64)
    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:134)
    at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:306)
    at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:135)
    at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50)
    at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:128)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$PassthruAdvice.invoke(SimpleBatchConfiguration.java:127)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
    at com.sun.proxy.$Proxy75.run(Unknown Source)
    at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.execute(JobLauncherCommandLineRunner.java:216)
    at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.executeLocalJobs(JobLauncherCommandLineRunner.java:233)
    at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.launchJobFromProperties(JobLauncherCommandLineRunner.java:125)
    at org.springframework.boot.autoconfigure.batch.JobLauncherCommandLineRunner.run(JobLauncherCommandLineRunner.java:119)
    at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:800)
    at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:784)
    at org.springframework.boot.SpringApplication.afterRefresh(SpringApplication.java:771)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175)
ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199

1 Answers1

2

Spring tries to inject a constructor-arg of type int, but the value is null.

null cannot be converted into an int, thats why you face the exception.

From your description I would guess, that the spring expression

#{jobParameters['commit.interval']}

results in null.

Use the debugger to see, what value is actually injected into bean 'transactionManager'