Skip to content

Commit 265a4e8

Browse files
committed
Support ability to run in development mode with postgresql for batch sample.
1 parent 01386e9 commit 265a4e8

File tree

4 files changed

+82
-0
lines changed

4 files changed

+82
-0
lines changed

spring-cloud-task-samples/batch-job/README.adoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,9 @@ mvn -Pnative native:compile
3838
----
3939
./target/batch-job
4040
----
41+
42+
== Run the application with a Postgesql test container
43+
[source,shell]
44+
----
45+
./mvnw spring-boot:test-run
46+
----

spring-cloud-task-samples/batch-job/pom.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,20 @@
5757
<groupId>org.mariadb.jdbc</groupId>
5858
<artifactId>mariadb-java-client</artifactId>
5959
</dependency>
60+
<dependency>
61+
<groupId>org.testcontainers</groupId>
62+
<artifactId>postgresql</artifactId>
63+
<scope>test</scope>
64+
</dependency>
65+
<dependency>
66+
<groupId>org.springframework.boot</groupId>
67+
<artifactId>spring-boot-testcontainers</artifactId>
68+
<scope>test</scope>
69+
</dependency>
70+
<dependency>
71+
<groupId>org.postgresql</groupId>
72+
<artifactId>postgresql</artifactId>
73+
</dependency>
6074
</dependencies>
6175

6276
<repositories>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 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+
*/
16+
17+
package io.spring;
18+
19+
import org.springframework.boot.test.context.TestConfiguration;
20+
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
21+
import org.springframework.context.annotation.Bean;
22+
import org.testcontainers.containers.PostgreSQLContainer;
23+
import org.testcontainers.utility.DockerImageName;
24+
25+
@TestConfiguration(proxyBeanMethods = false)
26+
class BatchJobTestConfiguration {
27+
28+
@Bean
29+
@ServiceConnection
30+
public PostgreSQLContainer<?> postgresSQLContainer() {
31+
return new PostgreSQLContainer(DockerImageName.parse("postgres:15.1"));
32+
}
33+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 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+
*/
16+
17+
package io.spring;
18+
19+
import org.springframework.boot.SpringApplication;
20+
21+
public class TestBatchJobApp {
22+
23+
public static void main(String[] args) {
24+
String[] myArgs = {"--spring.batch.jdbc.initialize-schema=always"};
25+
SpringApplication.from(BatchJobApplication::main).
26+
with(BatchJobTestConfiguration.class).
27+
run(myArgs);
28+
}
29+
}

0 commit comments

Comments
 (0)