You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I converted a simple batch app from v4 to v5. It has a single step that reads from Oracle and writes a CSV; it was using the map-based JobRepository so now I configured it on H2 as follows:
@BatchDataSource
@Bean
public DataSource h2Datasource() {
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
EmbeddedDatabase embeddedDatabase = builder
.addScript("classpath:org/springframework/batch/core/schema-h2.sql")
.setType(EmbeddedDatabaseType.H2)
.build();
return embeddedDatabase;
}
@Bean
@Primary
@ConfigurationProperties("spring.datasource")
public DataSourceProperties oracleDatasourceProperties() {
return new DataSourceProperties();
}
@Bean
@Primary
@ConfigurationProperties("spring.datasource.hikari")
public DataSource oracleDatasource() {
return oracleDatasourceProperties().initializeDataSourceBuilder().build();
}
I used neither @EnableBatchProcessing or DefaultBatchConfiguration and apparently everything worked but I noticed that the new batch was using two Oracle connections simultaneously instead of one. P6spy revealed that the 2nd connection was continuosly opened, committed and closed without writing anything. Finally I realized that the autoconfiguration created a TrasactionManager for the Oracle (primary) DataSource and used it to create the H2 JobRepository! So I solved creating it manually:
@Bean
public DataSourceTransactionManager h2TransactionManager() {
return new DataSourceTransactionManager(h2Datasource());
}
I wonder if autoconfiguration could be made smarter to avoid this kind of problem.
I know that you are going to release a ResourcelessJobRepository (#4679), so my use case will have a better solution but this misconfiguration can also happen if you want to put Spring-Batch tables in a dedicated Oracle schema.
Fell free to close this issue if you think that nothing can be improved on your side, however I hope that my experience will help someone else.
In any case, I think that documenting the two-DataSource setup would be useful. There is already a specific issue for this problem (#4675).
The text was updated successfully, but these errors were encountered:
I converted a simple batch app from v4 to v5. It has a single step that reads from Oracle and writes a CSV; it was using the map-based JobRepository so now I configured it on H2 as follows:
I used neither
@EnableBatchProcessing
orDefaultBatchConfiguration
and apparently everything worked but I noticed that the new batch was using two Oracle connections simultaneously instead of one. P6spy revealed that the 2nd connection was continuosly opened, committed and closed without writing anything. Finally I realized that the autoconfiguration created a TrasactionManager for the Oracle (primary) DataSource and used it to create the H2 JobRepository! So I solved creating it manually:I wonder if autoconfiguration could be made smarter to avoid this kind of problem.
I know that you are going to release a
ResourcelessJobRepository
(#4679), so my use case will have a better solution but this misconfiguration can also happen if you want to put Spring-Batch tables in a dedicated Oracle schema.Fell free to close this issue if you think that nothing can be improved on your side, however I hope that my experience will help someone else.
In any case, I think that documenting the two-DataSource setup would be useful. There is already a specific issue for this problem (#4675).
The text was updated successfully, but these errors were encountered: