IntelliJ IDEA
IntelliJ IDEA – the IDE for Professional Development in Java and Kotlin
Spring Debugger: Working With Dynamic Database Connections Just Got Simpler
While building Spring Boot applications, you can leverage Testcontainers to spin up any required services, such as a database or messaging broker, as Docker containers at application startup. This enables a ready-to-code setup, minimizing environment friction so you can focus on delivering high-quality, maintainable code.
For database-driven development, IntelliJ IDEA provides enterprise-grade, professional-level tooling out of the box. You can:
- Reverse-engineer JPA entities from an existing schema
- Generate Flyway or Liquibase migrations directly from your JPA models
- Access a suite of built-in integrations (e.g., SQL consoles, schema diff, and more) that help you maintain a clean, consistent database lifecycle
IntelliJ IDEA’s ergonomic UI and preconfigured environments allow you to code faster, refactor more smoothly, and catch potential issues before they become bugs. This means that using IntelliJ IDEA combined with Testcontainers is a productivity booster. However, there is just one problem…
Testcontainers map container ports to random host ports to avoid conflicts. Each time you restart your application, you must fetch the new mapped port and manually update IntelliJ IDEA’s DataSource connection properties.
JetBrains addressed this problem with the Spring Debugger plugin. It automatically registers the DataSource connection to any relational databases started by Testcontainers. Additionally, the DataSource connection will be automatically created while running Testcontainers tests. You can use the Spring Debugger plugin with IntelliJ IDEA Ultimate 2025.1.2 or any later versions.
NOTE: Spring Debugger automatic DataSource registration works with Testcontainers and Docker Compose too.
You can also watch the demonstration of Spring Debugger plugin’s automatic DataSource registration feature in this video.
Let’s explore this feature using a practical example.
Local development using Testcontainers
To follow along, clone the Spring Boot sample project from here.
This repository contains a Spring Boot REST API project using the starters Spring Web, Validation, Spring Data JPA, PostgreSQL Driver, Flyway Migration, and Testcontainers.
Open the project in IntelliJ IDEA Ultimate and run TestBookmarksApplication.java in debug mode to start the application.
As you can see, when you start the application, Testcontainers start a PostgreSQL database, and a PostgreSQL DataSource is automatically registered in IntelliJ IDEA’s Database tool window.
NOTE: The DataSource will be automatically registered ONLY when you start the application in debug mode.
When you stop the application, the registered DataSource will be automatically deleted from the Database tool window.
Debugging Testcontainers based tests
A DataSource is automatically registered both when running the application and when running tests. You can run your Testcontainers-based tests in debug mode, set a breakpoint, and explore the data in your database.
Here is an example of running a Spring Boot integration test that interacts with a PostgreSQL database started by Testcontainers.
As you can see, while running the test, we can set a breakpoint and verify the data in the database if needed.
Here is another example of debugging a Spring Data JPA Repository test using @DataJpaTest
.
Local development and testing with MongoDB
In addition to the relational databases, the automatic registration of the DataSource works for MongoDB as well.
Summary
IntelliJ IDEA’s automatic registration of Testcontainers data sources in the Database tool window eliminates the need for manually registering the DataSources. This makes local development and debugging of the Testcontainers tests using databases much simpler.
As of now, this feature works for relational databases and MongoDB only, but support for more databases will be added in upcoming IntelliJ IDEA versions.
To learn more about the features of the Spring Debugger plugin, please read the documentation.
What are you waiting for? Download the latest version of IntelliJ IDEA Ultimate and install the Spring Debugger plugin and try the features of its plugin for yourself.