Richie
Richie

Reputation: 5189

Putting into the jobExecutionContext - UnsupportedOperationException

I have the following step defined in my spring batch project. I've simplified the code for brevity.

@Bean
@JobScope
public JdbcCursorItemReader<MasterList> queryStagingDbReader(
        @Value("#{jobExecutionContext['" + ExecutionContextConstants.JOB_EXPORT_STAGING_PROMOTION_START_DATE_END_DATE_GROUPINGS +"']}")
        List<PromotionStartDateEndDateGrouping> promotionStartDateEndDateGroupings,
        @Value("#{jobExecutionContext}")Map<String, Object> jobExecutionContext) {  

    jobExecutionContext.put(ExecutionContextConstants.JOB_EXPORT_STAGING_WORKING_PROMOTION_START_DATE_END_DATE, "Hello");

}

My problem is that when I try to add to the jobExecutionContext as per the put statment above I get ...

Caused by: java.lang.UnsupportedOperationException: null
    at java.util.Collections$UnmodifiableMap.put(Collections.java:1457) ~

If this does not work how can I add to the jobExecutionContext?

thanks in advance

Upvotes: 0

Views: 1518

Answers (1)

Michael Minella
Michael Minella

Reputation: 21453

What are you receiving there is not the actual ExecutionContext. It's a Map with the values within the ExecutionContext. To obtain the actual ExecutionContext, you'd need to grab it from the JobExecution itself. That being said, in most cases, StepScope is more appropriate or the native singleton.

Upvotes: 2

Related Questions