Ollama Dev Service

A service providing an Ollama model inference service for development and testing purposes.

It works with Spring Boot libraries that support Ollama, including:

If a native Ollama connection is detected, for example, if you’re already running the Ollama application on your laptop, the Ollama Dev Service will not start a container and the native service will be used instead. The detection targets the URL configured via spring.ai.ollama.base-url, or http://localhost:11434 if not set. You can force the use of the container via the arconia.dev.services.ollama.ignore-native-service property.

Dependencies

First, you need to add the Dev Service dependency to your project.

  • Gradle

  • Maven

dependencies {
  testAndDevelopmentOnly "io.arconia:arconia-dev-services-ollama"
}
<dependency>
    <groupId>io.arconia</groupId>
    <artifactId>arconia-dev-services-ollama</artifactId>
    <scope>runtime</scope>
    <optional>true</optional>
</dependency>

You can optionally include the Spring Boot DevTools dependency to enable live reload of your application during development.

  • Gradle

  • Maven

dependencies {
  developmentOnly "org.springframework.boot:spring-boot-devtools"
}
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <scope>runtime</scope>
    <optional>true</optional>
</dependency>

When you use the Spring Boot DevTools in your project and run the application in dev mode, Arconia keeps 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. Changes to the configuration of a Dev Service take effect once you stop and start the application again.

Running the Application

When using the Arconia Dev Services, you can keep running your application as you normally would. The Dev Services will automatically start when you run your application.

  • Gradle

  • Maven

  • CLI

./gradlew bootRun
./mvnw spring-boot:run
arconia dev
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) nor requires you to define a separate @SpringBootApplication class for configuring Testcontainers.

Your @SpringBootTest integration tests use the Dev Service with no additional configuration.

By default, when running the application in dev mode, multiple applications running simultaneously use the same Ollama Dev Service: the application connects to a running Ollama Dev Service started by another application if available, or else starts its own that other applications can discover in turn. This requires the Spring AI Ollama module on the classpath: applications using only the OpenAI-compatible integration always start their own container. To always start a container for the application alone, set the arconia.dev.services.ollama.reuse-strategy property to none. Learn more about Reusing Dev Services.

Pulling Models

By default, the Ollama Dev Service starts without any model. You can have one or more models pulled automatically once the container is ready via the models property. They are pulled in the order they are declared.

arconia:
  dev:
    services:
      ollama:
        models:
          - qwen3:0.6b
          - nomic-embed-text:v1.5

The first pull downloads the entire model and can take a long time. To keep the downloaded models across application runs and tests, mount a host directory as the model store of Ollama:

arconia:
  dev:
    services:
      ollama:
        volumes:
          - host-path: ${user.home}/.ollama
            container-path: /root/.ollama

Setting the reuse-strategy property to testcontainers also avoids the cost at every application restart in dev mode, but the container is then no longer discoverable by other applications, and it doesn’t apply to tests.

Only containers started by the application are affected. When the application connects to a container started by another application, its models are left untouched.

Spring AI OpenAI Compatibility

When the Spring AI OpenAI module is on the classpath, the Ollama Dev Service automatically configures the OpenAI client to use the Ollama-compatible API endpoint. The spring.ai.openai.base-url and spring.ai.openai.api-key properties are set dynamically, pointing to the Ollama container when available or to the native Ollama service otherwise.

While the Ollama Dev Service is enabled, these properties take precedence over any user-defined configuration, and the API key is set to ollama.

If you want your application to use a real OpenAI endpoint in dev or test mode, opt out of the compatibility layer via arconia.dev.services.ollama.openai-compatibility=false. The Ollama Dev Service keeps running and your spring.ai.openai.* configuration is left untouched, which is useful when you use Ollama and OpenAI side by side. Disabling the Ollama Dev Service altogether via arconia.dev.services.ollama.enabled=false also works.

Configuring the Dev Service

You can configure the Dev Service via configuration properties.

Property Default Description

arconia.dev.services.ollama.enabled

true

Whether the dev service is enabled.

arconia.dev.services.ollama.image-name

ollama/ollama

Full name of the container image used in the dev service.

arconia.dev.services.ollama.environment

{}

Environment variables to set in the service.

arconia.dev.services.ollama.network-aliases

[]

Additional hostnames the dev service container is reachable by on the shared network, next to the name of the dev service. Only applicable when the shared network is enabled.

arconia.dev.services.ollama.port

0

Fixed port for exposing the Ollama inference service port to the host. When it’s 0 (default), a random available port is assigned dynamically.

arconia.dev.services.ollama.resources

[]

Resources from the classpath or host filesystem to copy into the container. They can be files or directories that will be copied to the specified destination path inside the container at startup and are immutable (read-only).

arconia.dev.services.ollama.reuse-strategy

framework

Strategy for reusing a running container for the dev service across applications or restarts. Only applicable in dev mode. See Reusing Dev Services.

arconia.dev.services.ollama.startup-timeout

120s

Maximum waiting time for the service to start, counted from the container start.

arconia.dev.services.ollama.volumes

[]

Files or directories to mount from the host filesystem into the container. They are mounted at the specified destination path inside the container at startup and are mutable (read-write). Changes in either the host or the container will be immediately reflected in the other.

arconia.dev.services.ollama.ignore-native-service

false

Whether to ignore an Ollama native service available on the host, but always use the container instead.

arconia.dev.services.ollama.models

[]

Names of the models to pull into the dev service once the container is ready, such as qwen3:0.6b. They are pulled in the order they are declared. When empty (default), no model is pulled.

arconia.dev.services.ollama.openai-compatibility

true

Whether to configure the Spring AI OpenAI client to use the OpenAI-compatible API exposed by the dev service, when the Spring AI OpenAI module is on the classpath.

Disabling the Dev Service

Set the arconia.dev.services.ollama.enabled property to false to disable the Dev Service. To disable it in one mode only, use the profile Arconia activates for that mode (see Profiles), for example in an application-test.yml file to disable it in tests:

arconia:
  dev:
    services:
      ollama:
        enabled: false

To disable it for a single test class, set the property with @SpringBootTest(properties = …​) or @TestPropertySource. To disable all the Dev Services at once, set arconia.dev.services.enabled to false.