I'm building a RAG pipeline with Spring Boot 3.2, Spring AI 1.0.0, and a local Llama 3.2 model running on Ollama. When I start the application and try to use ChatClient, I get the following error: org.springframework.web.client.ResourceAccessException: I/O failed on POST request for "http://localhost:11434/api/chat": Connection refused
My configuration in application.yml is:
spring:
ai:
ollama:
base-url: http://localhost:11434
chat:
options:
model: llama3.2
The dependency in pom.xml is spring-ai-ollama-spring-boot-starter. The service where I inject the client is:
@Service
public class RagService {
private final ChatClient chatClient;
public RagService(ChatClient.Builder chatClientBuilder) {
this.chatClient = chatClientBuilder.build();
}
// ...
}
I've verified that:
Ollama is installed and the model is downloaded (ollama list shows llama3.2:latest).
I can make a direct request with curl http://localhost:11434/api/chat and it works.
Port 11434 is free and no other process is using it.
If I start Ollama manually with ollama serve after starting the Spring Boot application, the error persists until I restart the application. Is Spring AI not retrying the connection? Do I need to configure a ConnectionFactory or a custom RestClient so that the application waits for Ollama to become available?