PostgreSQL Dev Service
When your application needs a relational database (such as when using Spring Data JDBC or Spring Data JPA), you can use the PostgreSQL Dev Service to automatically start a PostgreSQL database or one of its variants (such as PGVector when working with vectors in LLM-powered applications). This enables you to develop and test your application without having to manually start and manage a database server.
Dependencies
First, you need to add the PostgreSQL Dev Service dependency to your project. You can also include the Spring Boot DevTools dependency to enable live reload of your application during development.
dependencies {
developmentOnly "org.springframework.boot:spring-boot-devtools"
testAndDevelopmentOnly "io.arconia:arconia-dev-services-postgresql"
}
When you use the Spring Boot DevTools in your project, Arconia will keep the Dev Services running while you make changes to your code instead of restarting them with the application. This allows you to see the changes in real-time without having to restart the Dev Services. |
Running the Application
Unlike the lower-level Testcontainers support in Spring Boot, Arconia doesn’t require special tasks to run your application when using Dev Services (./gradlew bootTestRun
or ./mvnw spring-boot:test-run
). You can simply run your application using the usual tasks provided by the Spring Boot plugins for Gradle or Maven.
-
Gradle:
./gradlew bootRun
-
Maven:
./mvnw spring-boot:run
The Dev Service will automatically start when you run your application.
Your integration tests will automatically use the Dev Services without any additional configuration.
Customizing the Dev Service
You can customize the Dev Service via configuration properties, such as changing the image name or not reusing the service across multiple applications.
arconia:
dev:
services:
postgresql:
image-name: pgvector/pgvector:pg17
reusable: false
Disabling the Dev Service
If you want to disable the Dev Service, you can do so via configuration properties.
arconia:
dev:
services:
postgresql:
enabled: false
You can enable/disable the Dev Service for a specific test class by using the @TestProperty annotation or equivalent Spring testing utilities.
|
You can enable/disable the Dev Service for a specific application mode (development, test, production), relying on one of the profiles which are automatically configured by Arconia (see Profiles). |