开发者

Optional job parameters in Spring Batch

Is it possible make a job parameter optional in the sense that it evaluates to null if it is not specified instead of throwing an exception?

What I'm after is something like a

<bean id="fileNamePattern" class="java.lang.String" scope=开发者_JS百科"step">
    <constructor-arg value="#{jobParameters[fileNamePattern]}" />
</bean>

that I could pass as a property to another bean that handles the case where fileNamePattern is not specified.


Optional jobParameters do come across as null. The issue you have here is trying to create a java.lang.String with null. You could implement your own bean that knows how to handle null appropriately of course. However, there is another option.

The most common option, is to place the jobParameter directly into the property of the bean you have using fileNamePattern on. Of course, this will require that bean be scoped as "step". Here is a very simple example of what I mean.

<bean id="helloWorld"
    class="com.foo.example.HelloWorldTasklet" scope="step">
    <property name="someOptionalParameter" value="#{jobParameters[someOptionalParameter]}" />
</bean>

Another option would be to use a factory bean (of your own implementation) instead of java.lang.String.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜