This is an example of configuring a MySQL integration test based on Testcontainers utilizing @ServiceConnection in Spring Boot 3.1+
- Language:
Kotlin 1.9.25 - JVM Target:
Java 21 (Toolchain) - Build Tool:
Gradle (Kotlin DSL) - Spring Boot:
3.5.4
- kotlin("jvm"):
1.9.25-Kotlin → JVM compile - kotlin("plugin.spring"):
1.9.25-Kotlin + Spring plugin - kotlin("plugin.jpa"):
1.9.25-JPA entity no-arg/open plugin - org.springframework.boot:
3.5.4-Spring Boot plugin - io.spring.dependency-management:
1.1.7-dependency BOM and mangement
- org.springframework.boot:spring-boot-starter
- org.springframework.boot:spring-boot-starter-data-jpa
- org.springframework.boot:spring-boot-starter-test
- org.springframework.boot:spring-boot-testcontainers
- com.mysql:mysql-connector-j
- org.testcontainers:mysql
- org.junit.platform:junit-platform-launcher
- org.jetbrains.kotlin:kotlin-reflect
- org.jetbrains.kotlin:kotlin-test-junit5
.
├── main
│ ├── kotlin.com.chapakook.lab.springtestcontainers
│ │ ├── domain.user
│ │ │ ├── User.kt
│ │ │ └── UserRepository.kt
│ │ └── SpringTestcontainersApplication.kt
│ └── resources
│ └── application.yaml
└── com.chapakook.lab.springtestcontainers.domain.user
├── UserRepositoryTest.kt
└── UserRepositoryTestWithServiceConnection.kt
spring:
application:
name: service-connection
jpa:
hibernate:
ddl-auto: update
show-sql: true