chore: keep docker compose dependency with test scope.

This commit is contained in:
Josep Maria Formentí Serra 2024-05-18 14:16:50 +02:00
parent 68dfdddd4d
commit 5aedb47310
4 changed files with 14 additions and 25 deletions

View file

@ -68,10 +68,6 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-docker-compose</artifactId>
</dependency>
<!-- Databases - Uses H2 by default -->
<dependency>
@ -122,6 +118,11 @@
<artifactId>spring-boot-testcontainers</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-docker-compose</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>

View file

@ -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

View file

@ -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 @@ import org.testcontainers.containers.MySQLContainer;
@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);
}
}

View file

@ -70,9 +70,6 @@ public class PostgresIntegrationTests {
public static void main(String[] args) {
new SpringApplicationBuilder(PetClinicApplication.class) //
.profiles("postgres") //
.properties( //
"spring.docker.compose.profiles.active=postgres" //
) //
.listeners(new PropertiesLogger()) //
.run(args);
}