Integrating DeepSeek Large Language Model with Spring Boot to Build an AI Chat Application
This guide demonstrates how to create a Spring Boot backend that integrates DeepSeek's large language model via the Spring AI OpenAI starter, covering project setup, dependency configuration, API key management, and a sample controller that provides AI-powered chat responses such as weather forecasts.
In the digital age AI is pervasive, and Spring Boot remains a popular Java framework for building enterprise applications.
This article shows how to combine Spring Boot with DeepSeek, a new large language model (LLM) provider, to develop AI-powered services such as chatbots, document processing, or code generation.
Project creation : Using the Spring Initializr, select the Web and AI (OpenAI) starters; the generated pom.xml includes the necessary dependencies.
<properties>
<java.version>17</java.version>
<spring-ai.version>1.0.0-M5</spring-ai.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-openai-spring-boot-starter</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-bom</artifactId>
<version>${spring-ai.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>Configure OpenAI parameters : Obtain an API key from SiliconFlow (or other providers) and set the key, base URL, and model name in application.yml .
spring:
ai:
openai:
api-key: YOUR_API_KEY
base-url: https://api.siliconflow.cn
chat:
options:
model: deepseek-ai/DeepSeek-R1-Distill-Llama-8BThe chosen model “deepseek-ai/DeepSeek-R1-Distill-Llama-8B” is the free conversational model provided by SiliconFlow.
Implementing the AI controller : A simple ChatBotController uses ChatClient to forward user messages to the model and return the generated content.
package com.summer.springai.controller;
import groovy.util.logging.Slf4j;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.*;
@RestController
@CrossOrigin(origins = "*")
@Slf4j
public class ChatBotController {
private final ChatClient chatClient;
public ChatBotController(ChatClient.Builder builder) {
this.chatClient = builder.defaultSystem(
"You are a weather forecaster. When a date is provided, output Suzhou weather forecast in markdown, ending with: Thank you for your inquiry, I am Yuqing."
).build();
}
@GetMapping("/chat/{message}")
public String chat(@PathVariable("message") String message) {
return chatClient.prompt()
.user(message)
.call()
.content();
}
}After building and running the application, accessing http://localhost:8080/ai/chat/2025年2月12日 returns a weather forecast generated by the DeepSeek model.
The article concludes with a brief note that the same approach can be extended to output JSON, store results in a database, or perform data collection for enterprise projects.
Note: The final part of the source contains promotional material unrelated to the technical tutorial.
Java Architect Essentials
Committed to sharing quality articles and tutorials to help Java programmers progress from junior to mid-level to senior architect. We curate high-quality learning resources, interview questions, videos, and projects from across the internet to help you systematically improve your Java architecture skills. Follow and reply '1024' to get Java programming resources. Learn together, grow together.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.