Skip to content

Commit 090ae31

Browse files
author
Mattias Jiderhamn
committed
Simplify subclassing DefaultBatchConfigurer
1 parent 164bf17 commit 090ae31

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/DefaultBatchConfigurer.java

+12-7
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ public DefaultBatchConfigurer(DataSource dataSource) {
5858
setDataSource(dataSource);
5959
}
6060

61+
protected DataSource getDataSource() {
62+
return dataSource;
63+
}
64+
6165
@Override
6266
public JobRepository getJobRepository() {
6367
return jobRepository;
@@ -81,14 +85,15 @@ public JobExplorer getJobExplorer() {
8185
@PostConstruct
8286
public void initialize() {
8387
try {
84-
if(dataSource == null) {
88+
if(getDataSource() == null) {
8589
logger.warn("No datasource was provided...using a Map based JobRepository");
8690

87-
if(this.transactionManager == null) {
88-
this.transactionManager = new ResourcelessTransactionManager();
91+
PlatformTransactionManager transactionManager = this.getTransactionManager();
92+
if(transactionManager == null) {
93+
transactionManager = new ResourcelessTransactionManager();
8994
}
9095

91-
MapJobRepositoryFactoryBean jobRepositoryFactory = new MapJobRepositoryFactoryBean(this.transactionManager);
96+
MapJobRepositoryFactoryBean jobRepositoryFactory = new MapJobRepositoryFactoryBean(transactionManager);
9297
jobRepositoryFactory.afterPropertiesSet();
9398
this.jobRepository = jobRepositoryFactory.getObject();
9499

@@ -99,7 +104,7 @@ public void initialize() {
99104
this.jobRepository = createJobRepository();
100105

101106
JobExplorerFactoryBean jobExplorerFactoryBean = new JobExplorerFactoryBean();
102-
jobExplorerFactoryBean.setDataSource(this.dataSource);
107+
jobExplorerFactoryBean.setDataSource(this.getDataSource());
103108
jobExplorerFactoryBean.afterPropertiesSet();
104109
this.jobExplorer = jobExplorerFactoryBean.getObject();
105110
}
@@ -119,8 +124,8 @@ protected JobLauncher createJobLauncher() throws Exception {
119124

120125
protected JobRepository createJobRepository() throws Exception {
121126
JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
122-
factory.setDataSource(dataSource);
123-
factory.setTransactionManager(transactionManager);
127+
factory.setDataSource(getDataSource());
128+
factory.setTransactionManager(getTransactionManager());
124129
factory.afterPropertiesSet();
125130
return factory.getObject();
126131
}

0 commit comments

Comments
 (0)