Support ability to run in development mode with postgresql for batch sample.

This commit is contained in:
Glenn Renfro
2023-09-13 17:18:48 -04:00
parent 01386e9030
commit 265a4e8ae9
4 changed files with 82 additions and 0 deletions

View File

@@ -38,3 +38,9 @@ mvn -Pnative native:compile
----
./target/batch-job
----
== Run the application with a Postgesql test container
[source,shell]
----
./mvnw spring-boot:test-run
----

View File

@@ -57,6 +57,20 @@
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-testcontainers</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
</dependencies>
<repositories>

View File

@@ -0,0 +1,33 @@
/*
* Copyright 2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.spring;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.context.annotation.Bean;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.utility.DockerImageName;
@TestConfiguration(proxyBeanMethods = false)
class BatchJobTestConfiguration {
@Bean
@ServiceConnection
public PostgreSQLContainer<?> postgresSQLContainer() {
return new PostgreSQLContainer(DockerImageName.parse("postgres:15.1"));
}
}

View File

@@ -0,0 +1,29 @@
/*
* Copyright 2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.spring;
import org.springframework.boot.SpringApplication;
public class TestBatchJobApp {
public static void main(String[] args) {
String[] myArgs = {"--spring.batch.jdbc.initialize-schema=always"};
SpringApplication.from(BatchJobApplication::main).
with(BatchJobTestConfiguration.class).
run(myArgs);
}
}