Define an in-memory JobRepository
A few things here:
- If you have a
DataSource
configured in yourApplicationContext
, by default Spring Batch will try to use it. - In order to not use a
DataSource
when one is available within theApplicationContext
, you'll need to create your ownBatchConfigurer
. You can do that by extending theDefaultBatchConfigurer
. - Don't use the
MapJobRepository
except only for testing purposes. I has a number of issues (thread safety, etc) and is not recommended for production use. Use an in memory database like HSQLDB instead (you'll still need to create your ownBatchConfigurer
to do so).
With SpringBoot 2.x, the solution is simpler.
You have to extend the DefaultBatchConfigurer
class like this:
@Component
public class NoPersistenceBatchConfigurer extends DefaultBatchConfigurer {
@Override
public void setDataSource(DataSource dataSource) {
}
}
Without datasource, the framework automatically switches to use the MapJobRepository
.