diff --git a/pom.xml b/pom.xml
index 8cf4db093d8..601a71d4f28 100644
--- a/pom.xml
+++ b/pom.xml
@@ -68,10 +68,6 @@
spring-boot-starter-test
test
-
- org.springframework.boot
- spring-boot-docker-compose
-
@@ -122,6 +118,11 @@
spring-boot-testcontainers
test
+
+ org.springframework.boot
+ spring-boot-docker-compose
+ test
+
org.testcontainers
junit-jupiter
diff --git a/readme.md b/readme.md
index 03cfcf6361a..f290a416902 100644
--- a/readme.md
+++ b/readme.md
@@ -52,13 +52,13 @@ A similar setup is provided for MySQL and PostgreSQL if a persistent database co
You only need to pass the Spring Boot profile at the time of running the application:
```bash
-./mvnw spring-boot:run -Dspring-boot.run.profiles=mysql
+./mvnw spring-boot:test-run -Dstart-class=org.springframework.samples.petclinic.MysqlTestApplication
```
or
```bash
-./mvnw spring-boot:run -Dspring-boot.run.profiles=postgres
+./mvnw spring-boot:test-run -Dstart-class=org.springframework.samples.petclinic.PostgresIntegrationTests
```
## Test Applications
diff --git a/src/test/java/org/springframework/samples/petclinic/MysqlTestApplication.java b/src/test/java/org/springframework/samples/petclinic/MysqlTestApplication.java
index a3ee84bb01d..76adefa7534 100644
--- a/src/test/java/org/springframework/samples/petclinic/MysqlTestApplication.java
+++ b/src/test/java/org/springframework/samples/petclinic/MysqlTestApplication.java
@@ -16,12 +16,8 @@
package org.springframework.samples.petclinic;
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
-import org.springframework.context.annotation.Bean;
+import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Profile;
-import org.testcontainers.containers.MySQLContainer;
/**
* PetClinic Spring Boot Application.
@@ -32,15 +28,10 @@
@Configuration
public class MysqlTestApplication {
- @ServiceConnection
- @Profile("mysql")
- @Bean
- static MySQLContainer> container() {
- return new MySQLContainer<>("mysql:8.2");
- }
-
public static void main(String[] args) {
- SpringApplication.run(PetClinicApplication.class, "--spring.profiles.active=mysql");
+ new SpringApplicationBuilder(PetClinicApplication.class) //
+ .profiles("mysql") //
+ .run(args);
}
}
diff --git a/src/test/java/org/springframework/samples/petclinic/PostgresIntegrationTests.java b/src/test/java/org/springframework/samples/petclinic/PostgresIntegrationTests.java
index 18945a57038..45226deb895 100644
--- a/src/test/java/org/springframework/samples/petclinic/PostgresIntegrationTests.java
+++ b/src/test/java/org/springframework/samples/petclinic/PostgresIntegrationTests.java
@@ -16,13 +16,6 @@
package org.springframework.samples.petclinic;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.jupiter.api.Assumptions.assumeTrue;
-
-import java.util.Arrays;
-import java.util.LinkedList;
-import java.util.List;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.jupiter.api.BeforeAll;
@@ -47,6 +40,13 @@
import org.springframework.web.client.RestTemplate;
import org.testcontainers.DockerClientFactory;
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
+
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { "spring.docker.compose.skip.in-tests=false", //
"spring.docker.compose.profiles.active=postgres" })
@ActiveProfiles("postgres")
@@ -70,9 +70,6 @@ static void available() {
public static void main(String[] args) {
new SpringApplicationBuilder(PetClinicApplication.class) //
.profiles("postgres") //
- .properties( //
- "spring.docker.compose.profiles.active=postgres" //
- ) //
.listeners(new PropertiesLogger()) //
.run(args);
}