CoderSathi
  • Tutorial
    • Java Tutorial
    • Swing Tutorial
    • JDBC Tutorial
    • Java String Tutorial
    • Servlet and JSP Tutorial
  • Mongo DB
  • AWS
  • DevOps
  • Linux
  • Git
Home > Java > Integrate Spring AI with DeepSeek AI

Java Tutorial

  • Introduction
    • What is Java
    • History Of Java
    • Install Java
    • What is JVM
    • JDK vs JRE vs JVM
    • Java Bytecode
    • OOP vs POP
    • Compile and Run Java
  • Tokens, Expressions and Control Structures
    • Primitive data types
    • Integers
    • Floating Points
    • Characters
    • Booleans
    • User Defined Data Type
    • Declarations
    • Constants
    • Identifiers
    • Literals
    • Type Conversion and Casting
    • Variables
    • Default Variable Initialization
    • Command Line Arguments
    • Arrays of Primitive Types
    • Comment Syntax
    • Garbage Collection
    • Expressions
    • Operators
    • Arithmetic Operator
    • Bitwise and Shift Operator
    • Comparison or Relational Operators
    • Logical Operators
    • Assignment Operators
    • Ternary Operator
    • Increment and Decrement Operator
    • Control Statements
  • OOP Concepts
    • Class and Object
    • Create Class Instance
    • Method
    • Abstraction
    • Encapsulation
    • this keyword
    • Constructor
    • Pass by Value
    • Access Modifier/Control
    • Polymorphism
    • Method Overloading vs Method Overriding
    • Recursion
    • Nested and Inner Class
  • Inheritance and Packaging
    • Inheritance
    • extends Keyword
    • super Keyword
    • Object Class
    • Abstract class
    • Final Class
    • Java Package
    • Interface
  • Handling Error/ Exceptions
    • What is Exception
    • Exception Handling Keywords
    • Common Java Errors
    • User Defined Exception
    • Throwing and re-throwing Exception
    • finally Block
  • Strings
    • Java String Tutorial
  • Threads
    • Introduction
    • Create Thread
    • Thread Lifecycle
    • Thread Priority
    • Thread Synchronization
    • Inner Thread Communication
    • Thread Deadlock
  • IO and Streams
    • java.io Package
    • Files and Directories
    • Byte Stream
    • Character Stream
    • Console Input and Output
    • Serializable and Deserializable
  • Core Packages
    • java.lang Package
    • Math
    • Wrapper Classes
    • java.lang.Number
    • Double
    • Float
    • Integers
    • java.lang.Byte
    • java.lang.Short
    • java.lang.Long
    • java.lang.Character
    • java.lang.Boolean
    • java.util package
    • Vector Class
    • Stack Class
    • Dictionary Class
    • Hashtable
    • Enumeration or Enum
    • Generate Random Number
  • Holding Collection of Data
    • Arrays
    • Map
    • List
    • Set
    • Collection Interface
    • Collections Class
    • ArrayList
    • HashSet
    • TreeSet
    • Comparator
  • Java Bean
    • What is Java Bean
    • Advantages and Disadvantages of Java Bean
    • Java Beans API
    • Introspection
    • Java Bean Properties
    • Bound and Constrained Properties
    • BeanInfo Interface
    • Customizers
    • Java Beans Persistence
    • BeanDescriptor

Integrate Spring AI with DeepSeek AI

Learn the concepts, implementation details, and practical steps with a clean developer-focused walkthrough.

Yuba Raj Kalathoki
By Yuba Raj Kalathoki
Last updated: July 1, 2026 Β· 6 min read Β· 0 Comments
Share: in X

In today’s AI-driven development landscape, integrating machine learning models into applications has become essential. When you integrate Spring AI with DeepSeek AI it unlocks powerful, customizable AI solutions. This guide walks you through both connecting a local DeepSeek AI instance and connecting DeepSeek API to a Spring Boot application, empowering you to harness AI capabilities while maintaining full control over your infrastructure.

Table of Contents

  • Prerequisites
  • Step 1: Set Up Spring Boot Project
  • Step 2: Configure Spring AI for DeepSeek
    • Use Local Deepseek with ollama
    • Use Deepseek API Key
  • Step 3: Create REST Controller
  • Step 4: Test Application
  • Troubleshooting Common Issues
  • Why Integrate Spring AI with Local DeepSeek AI?
  • Conclusion

Prerequisites

  1. Java JDK 17+ and Spring Boot 3.x
  2. Either run DeepSeek AI Locally or generate DeepSeek API Key

Step 1: Set Up Spring Boot Project

Create a new Spring Boot project using Spring Initializr with the dependencies below:

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.4.2</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.codersathi</groupId>
    <artifactId>deepseek-ai-demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>deepseek-ai-demo</name>
    <description>deepseek-ai-demo</description>
    <url/>
    <licenses>
        <license/>
    </licenses>
    <developers>
        <developer/>
    </developers>
    <scm>
        <connection/>
        <developerConnection/>
        <tag/>
        <url/>
    </scm>
    <properties>
        <java.version>17</java.version>
        <spring-ai.version>1.0.0-M5</spring-ai.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.ai</groupId>
            <artifactId>spring-ai-ollama-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>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </path>
                    </annotationProcessorPaths>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <repositories>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

</project>

If you want to use DeepSeek API Key then you need to add following depsndency instead of ollama:

 <dependency>
            <groupId>org.springframework.ai</groupId>
            <artifactId>spring-ai-openai-spring-boot-starter</artifactId>
 </dependency>

Meke sure to remove spring-ai-ollama-spring-boot-starter dependency from your pom.xml file if you are using DeepSeek API key. You don’t need to use seperate dependency to use DeepSeek API. It works with spring-ai-openai-spring-boot-starter dependency.

Step 2: Configure Spring AI for DeepSeek

Add DeepSeek connection properties to application.properties:

application.properties

Use Local Deepseek with ollama

Dependency:

<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-ollama-spring-boot-starter</artifactId>
</dependency>

If you are going to integrate Spring AI with local DeepSeek AI instance then use below configuration:

spring.ai.ollama.chat.enabled=true
spring.ai.ollama.chat.model=deepseek-coder-v2
spring.ai.ollama.base-url=http://localhost:11434

Use Deepseek API Key

Dependency:

 <dependency>
            <groupId>org.springframework.ai</groupId>
            <artifactId>spring-ai-openai-spring-boot-starter</artifactId>
 </dependency>

If you are going to integrate spring ai with DeepSeek AI API then you must generate Deepseek API Key to use below configuration:

spring.ai.openai.api-key=add-your-api-key-here
spring.ai.openai.base-url=https://api.deepseek.com
spring.ai.openai.chat.options.model=deepseek-chat
spring.ai.openai.embedding.enabled=false //Deepseek does not support embedding as of now

Step 3: Create REST Controller

Expose API endpoint for request processing and call DeepSeek AI model. You can call DeepSeek AI with ChatClient directly whether it is running in your local computer or calling directly Cloud DeepSeek API. This exact same code works for both local DeepSeek AI and Cloud DeepSeek AI.

ChatController.java

package com.codersathi.deepseekaidemo;

import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/ai")
@Slf4j
public class ChatController {

	private final ChatClient chatClient;

	public ChatController(ChatClient.Builder chatClientBuilder) {
		this.chatClient = chatClientBuilder.build();
	}

	@GetMapping("/chat")
	public String generate(@RequestParam(value = "message", defaultValue = "Tell me a joke") String message) {
		log.info("Generating response");
		return chatClient.prompt(message).call().content();
	}

}

Step 4: Test Application

Type following URL in your browser and you may see the response:

http://localhost:8080/ai/chat?message=what is java

Troubleshooting Common Issues

  • Connection Refused: Verify DeepSeek AI with the help of ollama is running on port 11434 if you are using DeepSeek AI locally otherwise, you need to check your API Key in the DeepSeek platform.

Why Integrate Spring AI with Local DeepSeek AI?

  • Data Privacy: Keep sensitive data on-premises.
  • Customization: Tailor DeepSeek AI models to your needs.
  • Performance: Reduce latency by processing data locally.
  • Cost Efficiency: Avoid cloud-based API fees.

Conclusion

In this post, we learned how to integrate Spring AI with local DeepSeek AI with example. Now, you can adjust this implementation as per your need. Good Luck πŸ™‚

Related Posts:

  • Most Frequently Asked Spring Boot Interview…
  • How to Run DeepSeek AI Locally Using Ollama: A…
  • Spring Data REST example.
  • How to Install Ollama on Windows, Linux, and macOS:…
  • How to Generate DeepSeek API Key: Step-by-Step Guide
  • Consistency and Availability in Distributed System
Tags:aideepseekjavaspring-aispring-boot
Was this article helpful?
← Previous ArticleHow to Generate DeepSeek API Key: Step-by-Step Guide
Next Article β†’Most Frequently Asked Spring Boot Interview Questions for 2025

Leave a Comment Cancel reply

You must be logged in to post a comment.

Recent Posts

  • How to implement Passwordless Authentication in Spring Boot: A Step-by-Step Guide
  • How to Use AWS CloudFront Signed URLs in Spring Boot?
  • How to Fix SSH Agent Forwarding on macOS: The Ultimate Guide for Developers
  • How to Read AWS Secrets Manager in Spring Boot (Step-by-Step)
  • How to Fix “Public Key Retrieval is not allowed” MySQL JDBC Error
CoderSathi

Your go-to resource for Java, Spring Boot, Microservices, AWS, and modern development tutorials.

Linkedin

Quick Links

  • About
  • Contact

Popular Topics

  • Java
  • Spring Boot
  • AWS
  • DevOps
  • MongoDB
  • Linux
  • Git
  • How to
Β© 2026 CoderSathi. All rights reserved. Privacy Policy Β· Sitemap