H2 accepts SQL MySQL rejects, so a green suite on H2 proves less than it appears to.
@SpringBootTest
@Testcontainers
class OrderRepositoryTest {
@Container
@ServiceConnection
static MySQLContainer<?> mysql = new MySQLContainer<>("mysql:8.4");
@Autowired OrderRepository repo;
}
@ServiceConnection wires the datasource automatically -
no spring.datasource.url property needed in the test.
Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.
Published 2026-08-11