Skip to content

Commit 850c27e

Browse files
committed
Fix datasource configuration in metrics sample
1 parent 93d911e commit 850c27e

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

spring-batch-samples/pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,6 @@
215215
<groupId>org.hsqldb</groupId>
216216
<artifactId>hsqldb</artifactId>
217217
<version>${hsqldb.version}</version>
218-
<scope>test</scope>
219218
</dependency>
220219
<dependency>
221220
<groupId>org.slf4j</groupId>

spring-batch-samples/src/main/java/org/springframework/batch/sample/metrics/BatchMetricsApplication.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,31 @@
1+
/*
2+
* Copyright 2022-2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package org.springframework.batch.sample.metrics;
217

18+
import javax.sql.DataSource;
19+
320
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
421
import org.springframework.beans.factory.annotation.Value;
522
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
623
import org.springframework.context.annotation.Bean;
724
import org.springframework.context.annotation.Import;
825
import org.springframework.context.annotation.PropertySource;
26+
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
27+
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
28+
import org.springframework.jdbc.support.JdbcTransactionManager;
929
import org.springframework.scheduling.annotation.EnableScheduling;
1030
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
1131

@@ -28,4 +48,16 @@ public ThreadPoolTaskScheduler taskScheduler(@Value("${thread.pool.size}") int t
2848
return threadPoolTaskScheduler;
2949
}
3050

51+
@Bean
52+
public DataSource dataSource() {
53+
return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.HSQL)
54+
.addScript("/org/springframework/batch/core/schema-hsqldb.sql")
55+
.build();
56+
}
57+
58+
@Bean
59+
public JdbcTransactionManager transactionManager(DataSource dataSource) {
60+
return new JdbcTransactionManager(dataSource);
61+
}
62+
3163
}

0 commit comments

Comments
 (0)