Issue Details (XML | Word | Printable)

Key: BATCH-115
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Dave Syer
Reporter: Robert Kasanicky
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Spring Batch

(some) samples launched from command line don't work

Created: 27/Aug/07 06:03 AM   Updated: 07/Aug/08 10:06 AM
Component/s: Samples
Affects Version/s: 1.0-m2
Fix Version/s: 1.0-m2
Security Level: Public (Public Issues)

Time Tracking:
Not Specified

File Attachments: 1. Text File samplesFix.patch (4 kB)
2. File simpleTaskletJob.launch (1 kB)



 Description  « Hide
When samples are run from command line the application context is created differently from a test case inherited from AbstractDependencyInjectionSpringContextTests. There are different sets of property value converters registered:

<property name="lengths" value="12, 3, 5, 9" /> is converted smoothly to an array of integers when run in a test case, but causes exception when run from command line using BatchCommandLineLauncher. This property declaration is found in simpleTaskletJob, fixedLengthImportJob, multilineJob, multilineOrderJob.

 All   Comments   Work Log   Change History   FishEye   Builds      Sort Order: Ascending order - Click to sort in descending order
Dave Syer added a comment - 28/Aug/07 02:48 AM
Can you attach a command line client that exhibits this behaviour?

Robert Kasanicky added a comment - 28/Aug/07 03:08 AM
I was launching the job from eclipse (not exactly "command line", but it doesn't matter I believe), so I attach the launch configuration.

I'm not sure this can be easily imported so here are the key settings:

main class: org.springframework.batch.execution.bootstrap.BatchCommandLineLauncher

arguments:
jobs/simpleTaskletJob.xml simpleTaskletJob

Dave Syer added a comment - 28/Aug/07 05:51 AM - edited
The launcher works if you put it in the project (and modify the project names if necessary).

The custom editor configurer needs to be added to the job configuration. Also the step scope registration:

<bean parent="customEditorConfigurer"/>

<!-- register the step scope with the application context -->
<bean class="org.springframework.batch.execution.scope.StepScope" />

If you have time, could you try some of the other samples this way and tell us (or attach a patch) which ones need to be fixed? P.S. I committed the above change to simpleTaskletJob.xml.

Robert Kasanicky added a comment - 28/Aug/07 07:04 AM
I'm attaching a patch that adds the bean declarations... this resolved most of the problems, but tradeJob and multilineOrderJob are still having some scope-related trouble with FlatFileOutputSource.

One more remark: adding "magical" bean declaration for each job feels like a workaround... I guess the BatchCommandLineLauncher should be refactored to handle the subtleties of creating appropriate application context?

Dave Syer added a comment - 28/Aug/07 07:27 AM
It's not really a workaround - e.g. if you used step scope in your job configuration you should expect to have to declare it. At some point we are going to have a custom namespace, and that can take care of the "magical" beans. In the meantime the samples serve as a reference point for best practice I guess.




Dave Syer added a comment - 28/Aug/07 07:51 AM
Fixed samples so they can be launched from command line. To make it easier they all have the same job name ("jobConfiguration") and the launcher is also committed to CVS now - it will work if the project names are execution and samples. Thanks for the patch - it helped a lot.

N.B. there is no logger output from most of the jobs - is that expected?

Robert Kasanicky added a comment - 28/Aug/07 08:37 AM
Yes, logging is another example of differences in context creation. The logging aspect is declared in the container definition so it does not apply to beans declared in job configuration when run from command line.

Is there a particular reason why BatchCommandLineLauncher creates the parent context first instead of creating the context at once from multiple configuration files? (it is sure not desirable to have inconsistencies between functional tests and manually running a job - I don't know which approach to context creation is better, but I believe only one should be used)

Douglas C. Kaminsky added a comment - 28/Aug/07 02:02 PM
Along the same lines, I had the problem that the 'step' scope was not available to jobs unless it was re-defined in the job configuration file since it was loaded as part of the simple-container-definition (imported from data-source-context).

I believe this is related to the issue I submitted regarding the use of simple-container-definition in sample projects (BATCH-94).

It seems that either a single context should be created for all of these beans or it should be advised that a separate configurable file be imported by all jobs - eg. batch-common.xml (as I have done in my development) which contains definitions every job should have, eg. the JobConfigurationRegistryBeanPostProcessor. I also used this to separate batch datasource from my 'normal' datasource to allow batch schema to exist separate from data which individual jobs are concerned with and so jobs are unaware of batch datasource.

Dave Syer added a comment - 07/Aug/08 10:06 AM
Assume closed as resolved and released