Hi, I've trouble with a jobParameter. I saw forum entries about "nullability" of a jobParameter but can't get it to work.
I'm using Spring-batch 2.0.4 with CommandLineJobRunner.
Use case:
There is a job running every day, or supposed to.
According to maintenance purposes it may not run some days.
Unfortunately, in this case, the next time it will be launch we need to specify a date from witch the batch should "restart".
But this date depends on "manual" calculation (some kind of business rules people in charge won't let us build in the code; there choice).
So I need the following behaviour for the job:
- it can run without jobParameter (calculate the correct date by itself)
- it can be run with a jobParameter (ex : dateInit(date)=2009/12/31)
Spring conf:
Problem:Code:<!-- Alimentation "principale" des données du distributeur --> <bean id="distributeurLoad" scope="step" class="...processor.DistributeurLoaderProcessor" autowire="byType"> <property name="dateInit" value="#{jobParameters[dateInit]}"/> </bean>
If I run the batch with a value for the parameter everything works fine.
But I couldn't find a way to launch without a value for the parameter.
It throws an exception when I tried an empty parameter value on the command line : dateInit(date)=
It throws an exception when I tried an empty value without type informations : dateInit=Code:java.lang.IllegalArgumentException: Date format is invalid: [], use yyyy/MM/dd at org.springframework.batch.core.converter.DefaultJobParametersConverter.getJobParameters(DefaultJobParametersConverter.java:95) at org.springframework.batch.core.launch.support.CommandLineJobRunner.start(CommandLineJobRunner.java:275) at org.springframework.batch.core.launch.support.CommandLineJobRunner.main(CommandLineJobRunner.java:448)
It throws an exception when I tried no parameter on the command lineCode:Caused by: java.lang.IllegalArgumentException: Cannot convert value of type [java.lang.String] to required type [java.util.Date]: no matching editors or conversion strategy found at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:231) at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:107) at org.springframework.beans.SimpleTypeConverter.convertIfNecessary(SimpleTypeConverter.java:47)
Question :Code:Caused by: java.lang.IllegalStateException: Cannot bind to placeholder: jobParameters[dateInit] at org.springframework.batch.core.scope.util.PlaceholderTargetSource$1.convertIfNecessary(PlaceholderTargetSource.java:140) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1294) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1250) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
How can I get a null value in a date jobParameter when launching with CommandLineJobRunner?
Thank you for your attention.
Happy new year !


Reply With Quote
I will need to figure out a way to mock/simulate it in my job unit test.
