ArrayList cannot be cast to org.springframework.batch.core.JobParameter

后端 未结 2 697
一向
一向 2021-01-15 09:02

I want to send a list from rest client to rest web service which will start a job in Spring Batch. Is that possible or must I save the list in database/flatfile before start

相关标签:
2条回答
  • 2021-01-15 09:26

    Batch jobs are meant to be Time based not Event based. So, you can't pass the information from Rest service to your Job instance. Before you trigger the job in your controller method either write the list in temporary flat file or store it in a database, from where your Job can read it.

    0 讨论(0)
  • 2021-01-15 09:44

    If you look at actual schema which stores meta data for spring batch you will see list of available types supported by job to be parameters (there is string_val, date_val, long_val, double_val). So when job is started each job parameter is persisted in DB with key_name as name of parameter and value stored in one of mentioned _val tables. type_cd gives a hint which type was used.

    Also documentation for JobParameter gives a hint what can be used as job parameter:

    Domain representation of a parameter to a batch job. Only the following types can be parameters: String, Long, Date, and Double. The identifying flag is used to indicate if the parameter is to be used as part of the identification of a job instance.

    I think best way would be either to create table in DB which stores list of parameters and pass id of that record as JobParameter or to serialize list to json and pass it as String in job as JobParameter. If you go with second option be aware that string_val is stored in DB as varchar 250 so limit is 250 characters.

    0 讨论(0)
提交回复
热议问题