Skip to content

AkashKobal/springboot-gemini-integration

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Spring Boot Gemini Integration

Production-ready Spring Boot application integrating Google Gemini (gemini-3-flash-preview) via Ollama Cloud.
Supports both Text Chat and Image + Text Chat using clean architecture and Thymeleaf UI.


✨ Features

  • βœ… Gemini Text Chat API
  • βœ… Gemini Image + Text Chat API (Vision)
  • βœ… Spring Boot REST API integration
  • βœ… Thymeleaf Web UI
  • βœ… Ollama Cloud model support
  • βœ… Production-ready service architecture
  • βœ… Clean DTO-based request/response structure
  • βœ… Multipart file upload support
  • βœ… Externalized configuration

🧠 Supported Model

gemini-3-flash-preview:cloud

Powered via:

https://ollama.com


πŸ— Project Architecture

springboot-gemini-integration
β”‚
β”œβ”€β”€ controller
β”‚   β”œβ”€β”€ GeminiController.java
β”‚   └── PageController.java
β”‚
β”œβ”€β”€ service
β”‚   └── GeminiService.java
β”‚
β”œβ”€β”€ dto
β”‚   β”œβ”€β”€ ChatRequest.java
β”‚   └── ChatResponse.java
β”‚
β”œβ”€β”€ config
β”‚   └── RestTemplateConfig.java
β”‚
β”œβ”€β”€ templates
β”‚   └── index.html
β”‚
└── application.yml

βš™οΈ Configuration

application.yml

server:
  port: 8080

gemini:
  api:
    url: http://localhost:11434/api/chat
    model: gemini-3-flash-preview:cloud

▢️ Running the Project

1. Start Ollama

ollama serve

2. Pull Gemini model

ollama pull gemini-3-flash-preview:cloud

3. Run Spring Boot

./mvnw spring-boot:run

or

mvn spring-boot:run

Application runs at:

http://localhost:8080

🌐 Web UI

Text Chat
Image + Text Chat

Accessible at:

http://localhost:8080

πŸ“‘ REST APIs


1. Text Chat API

Endpoint

POST /api/gemini/chat

Request

{
  "message": "Explain Spring Boot"
}

Response

{
  "response": "Spring Boot is a Java framework..."
}

2. Image + Text Chat API

Endpoint

POST /api/gemini/chat-with-image

Form Data

message: What is in this image?
image: file.jpg

πŸ§ͺ Example Curl

Text Chat

curl -X POST http://localhost:8080/api/gemini/chat \
-H "Content-Type: application/json" \
-d '{"message":"Explain AI"}'

Image Chat

curl -X POST http://localhost:8080/api/gemini/chat-with-image \
-F "message=Describe this image" \
-F "image=@test.png"

πŸ“Έ Screenshots

Text Chat UI

Text Chat

Image Chat UI

Image Chat


πŸ›  Tech Stack

  • Java 17+
  • Spring Boot 3+
  • Thymeleaf
  • RestTemplate
  • Ollama Cloud
  • Gemini Flash Preview
  • Maven

🧩 Key Components

GeminiService

Handles communication with Gemini model.

Supports:

  • Text chat
  • Image + Text chat
  • JSON parsing
  • Error handling

GeminiController

Provides REST APIs:

/api/gemini/chat
/api/gemini/chat-with-image

PageController

Provides Web UI integration via Thymeleaf.


πŸ”’ Production Ready Features

  • Layered architecture
  • Exception handling
  • External configuration
  • Multipart upload support
  • Clean separation of concerns

πŸš€ Future Enhancements

  • Multi-model support (Kimi, Qwen, Mistral)
  • Streaming responses
  • Chat history
  • Authentication
  • Docker support
  • Model router

πŸ‘¨β€πŸ’» Author

Akash Kobal

GitHub: https://github.com/AkashKobal


πŸ“„ License

MIT License


⭐ Support

If this project helped you, please star the repository ⭐

About

Spring Boot + Gemini AI integration using Ollama Cloud with support for text and image chat APIs.

Topics

Resources

Stars

Watchers

Forks

Contributors