Spring Batch Table Prefix when using Java Config
<p>My Spring Batch repository (deployed on an Oracle database) lies in a different schema such that I need to prepend the schema name.</p>

<p>When using XML configuration, this would be easy to do:</p>

<pre><code>&lt;job-repository id="jobRepository" table-prefix="GFA.BATCH_" /&gt;
</code></pre>

<p>However, as I use Java Config, this turns out to be more tricky.
The best solution I found is to have my Java Config class <code>extend DefaultBatchConfigurer</code> and override the <code>createJobRepository()</code> method: </p>

<pre><code>@Configuration
@EnableBatchProcessing
public class BatchConfiguration extends DefaultBatchConfigurer{
    @Autowired
    private DataSource dataSource;

    @Autowired
    private PlatformTransactionManager transactionManager;

    @Override
    protected JobRepository createJobRepository() throws Exception {
        JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
        factory.setDataSource(dataSource);
        factory.setTransactionManager(transactionManager);
        factory.setTablePrefix("GFA.BATCH_");
        factory.afterPropertiesSet();
        return factory.getObject();
    }
...
}
</code></pre>

<p>Compared to the XML solution, that's pretty much code! And it's not too logical either - my first guess was to provide an <code>@Bean</code> method as follows:</p>

<pre><code>@Bean
public JobRepository jobRepository() throws Exception {
    JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
    factory.setDataSource(dataSource);
    factory.setTransactionManager(transactionManager);
    factory.setTablePrefix("GFA.BATCH_");
    factory.afterPropertiesSet();
    return factory.getObject();
}
</code></pre>

<p>but this wouldn't work.</p>

<p>My question is:
Is my solution optimal or is there a better one? I would prefer to define a Bean instead of having to override some method of some class which is not very intuitive...
And obviously it would be even better if we could shorten the code to be somewhat close to the one-line code in the XML configuration.</p>