Sample Spring AI Application with several use cases
See the codeThis project demonstrates the integration of AI capabilities within a Spring Boot application, utilizing the Spring AI framework.
Currently, there are four @RestControllers that show Spring AI features:
pl.piomin.services.controller.PersonController - prompt template, chat memory, and structured output based on a simple example that asks AI model to generate some persons
pl.piomin.services.controller.WalletController - function calling that calculates a value of our wallet stored in local database in conjunction with the latest stock prices
pl.piomin.services.controller.StockController - RAG with a Pinecone vector store and OpenAI based on stock prices API
pl.piomin.services.controller.ImageController - image model and multimodality
The architecture is designed to be modular and scalable, focusing on demonstrating how AI features can be incorporated into Spring-based applications.
Follow these steps to run the application locally.
git clone https://github.com/piomin/spring-ai-showcase.git
cd spring-ai-showcase
By default, this sample Spring AI app connects to OpenAI. So, before running the app you must set a token:
export OPEN_AI_TOKEN=<YOUR_API_TOKEN>
mvn spring-boot:run
To enable integration with Mistral, we should activate the mistral-ai profile:
export MISTRAL_AI_TOKEN=<YOUR_API_TOKEN>
mvn spring-boot:run -Pmistral-ai
To enable integration with Ollama, we should activate the ollama-ai profile:
mvn spring-boot:run -Pollama-ai
Before that, we must run the model on Ollama, e.g.:
ollama run llava
To enable integration with Azure OpenAI, we should activate the azure-ai profile and activate the Spring Boot azure-ai profile:
mvn spring-boot:run -Pazure-ai -Dspring-boot.run.profiles=azure-ai
To enable integration with Anthropic Claude, we should activate the anthropic profile and activate the Spring Boot anthropic profile as well:
export ANTHROPIC_AI_TOKEN=<YOUR_API_TOKEN>
mvn spring-boot:run -Panthropic -Dspring-boot.run.profiles=anthropic
You should also export the Azure OpenAI credentials:
export AZURE_OPENAI_API_KEY=<YOUR_AZURE_OPENAI_API_KEY>
For scenarios with a vector store (StockController, ImageController) you need to export the following ENV:
export PINECONE_TOKEN=<YOUR_PINECONE_TOKEN>
For scenarios with a stock API (StockController, WalletController) you need to export the following ENV:
export STOCK_API_KEY=<YOUR_STOCK_API_KEY>
More details in the articles.
The application exposes several REST API endpoints organized by functionality. Below is a comprehensive list of all available endpoints:
/persons)Demonstrates prompt templates, chat memory, and structured output generation.
| Method | Endpoint | Description | Response Type |
|---|---|---|---|
| GET | /persons | Generate or return a list of 10 persons with random values | List<Person> |
| GET | /persons/{id} | Find and return person by ID from current list | Person |
/wallet)Demonstrates function calling with stock price calculations and wallet value analysis.
| Method | Endpoint | Description | Response Type |
|---|---|---|---|
| GET | /wallet/with-tools | Calculate current wallet value using latest stock prices with AI tools | String |
| GET | /wallet/highest-day/{days} | Find the day with highest wallet value in the last N days | String |
/stocks)Demonstrates RAG (Retrieval Augmented Generation) with Pinecone vector store for stock market analysis.
| Method | Endpoint | Description | Response Type |
|---|---|---|---|
| GET | /stocks/load-data | Load stock data for major companies (AAPL, MSFT, GOOG, AMZN, META, NVDA) into vector store | void |
| GET | /stocks/docs | Query vector store documents for growth trends | List<Document> |
| GET/POST | /stocks/v1/most-growth-trend | Find stock with most percentage growth (version 1) | String |
| GET/POST | /stocks/v1-1/most-growth-trend | Find stock with most percentage growth with enhanced search (version 1.1) | String |
| GET/POST | /stocks/v2/most-growth-trend | Find stock with most percentage growth using advanced RAG (version 2) | String |
/images)Demonstrates image model capabilities, multimodality, and image generation/analysis.
| Method | Endpoint | Description | Response Type |
|---|---|---|---|
| GET | /images/find/{object} | Find and return image containing the specified object | byte[] (PNG) |
| GET | /images/generate/{object} | Generate a new image containing the specified object | byte[] (PNG) |
| GET | /images/describe | Describe all images (static + dynamically generated) | String[] |
| GET | /images/describe/{image} | Describe items in a specific image and categorize them | List<Item> |
| GET | /images/load | Load image descriptions into vector store for similarity search | void |
| GET | /images/generate-and-match/{object} | Generate image with object and find similar images in vector store | List<Document> |
/api)Demonstrates dynamic API generation with chat memory for any entity type.
| Method | Endpoint | Description | Response Type |
|---|---|---|---|
| GET/POST | /api/{entity} | Generate a dynamic list of any entity type with random values | String |
| GET/POST | /api/{entity}/{id} | Find and return specific entity by ID from current list | String |
# Generate a list of persons
curl http://localhost:8080/persons
# Calculate wallet value with AI tools
curl http://localhost:8080/wallet/with-tools
# Load stock data into vector store
curl http://localhost:8080/stocks/load-data
# Find stock with most growth
curl http://localhost:8080/stocks/v2/most-growth-trend
# Generate an image with cats
curl http://localhost:8080/images/generate/cats --output cats.png
# Generate dynamic list of cars
curl http://localhost:8080/api/cars
/wallet/* and /stocks/* endpoints/stocks/*, /images/load, /images/generate-and-match/*)/images/generate/* and /images/generate-and-match/* endpoints28 followers · starred Dec 2025
Java
100.0%
Sample Spring AI Application with several use cases
See the codeThis project demonstrates the integration of AI capabilities within a Spring Boot application, utilizing the Spring AI framework.
Currently, there are four @RestControllers that show Spring AI features:
pl.piomin.services.controller.PersonController - prompt template, chat memory, and structured output based on a simple example that asks AI model to generate some persons
pl.piomin.services.controller.WalletController - function calling that calculates a value of our wallet stored in local database in conjunction with the latest stock prices
pl.piomin.services.controller.StockController - RAG with a Pinecone vector store and OpenAI based on stock prices API
pl.piomin.services.controller.ImageController - image model and multimodality
The architecture is designed to be modular and scalable, focusing on demonstrating how AI features can be incorporated into Spring-based applications.
Follow these steps to run the application locally.
git clone https://github.com/piomin/spring-ai-showcase.git
cd spring-ai-showcase
By default, this sample Spring AI app connects to OpenAI. So, before running the app you must set a token:
export OPEN_AI_TOKEN=<YOUR_API_TOKEN>
mvn spring-boot:run
To enable integration with Mistral, we should activate the mistral-ai profile:
export MISTRAL_AI_TOKEN=<YOUR_API_TOKEN>
mvn spring-boot:run -Pmistral-ai
To enable integration with Ollama, we should activate the ollama-ai profile:
mvn spring-boot:run -Pollama-ai
Before that, we must run the model on Ollama, e.g.:
ollama run llava
To enable integration with Azure OpenAI, we should activate the azure-ai profile and activate the Spring Boot azure-ai profile:
mvn spring-boot:run -Pazure-ai -Dspring-boot.run.profiles=azure-ai
To enable integration with Anthropic Claude, we should activate the anthropic profile and activate the Spring Boot anthropic profile as well:
export ANTHROPIC_AI_TOKEN=<YOUR_API_TOKEN>
mvn spring-boot:run -Panthropic -Dspring-boot.run.profiles=anthropic
You should also export the Azure OpenAI credentials:
export AZURE_OPENAI_API_KEY=<YOUR_AZURE_OPENAI_API_KEY>
For scenarios with a vector store (StockController, ImageController) you need to export the following ENV:
export PINECONE_TOKEN=<YOUR_PINECONE_TOKEN>
For scenarios with a stock API (StockController, WalletController) you need to export the following ENV:
export STOCK_API_KEY=<YOUR_STOCK_API_KEY>
More details in the articles.
The application exposes several REST API endpoints organized by functionality. Below is a comprehensive list of all available endpoints:
/persons)Demonstrates prompt templates, chat memory, and structured output generation.
| Method | Endpoint | Description | Response Type |
|---|---|---|---|
| GET | /persons | Generate or return a list of 10 persons with random values | List<Person> |
| GET | /persons/{id} | Find and return person by ID from current list | Person |
/wallet)Demonstrates function calling with stock price calculations and wallet value analysis.
| Method | Endpoint | Description | Response Type |
|---|---|---|---|
| GET | /wallet/with-tools | Calculate current wallet value using latest stock prices with AI tools | String |
| GET | /wallet/highest-day/{days} | Find the day with highest wallet value in the last N days | String |
/stocks)Demonstrates RAG (Retrieval Augmented Generation) with Pinecone vector store for stock market analysis.
| Method | Endpoint | Description | Response Type |
|---|---|---|---|
| GET | /stocks/load-data | Load stock data for major companies (AAPL, MSFT, GOOG, AMZN, META, NVDA) into vector store | void |
| GET | /stocks/docs | Query vector store documents for growth trends | List<Document> |
| GET/POST | /stocks/v1/most-growth-trend | Find stock with most percentage growth (version 1) | String |
| GET/POST | /stocks/v1-1/most-growth-trend | Find stock with most percentage growth with enhanced search (version 1.1) | String |
| GET/POST | /stocks/v2/most-growth-trend | Find stock with most percentage growth using advanced RAG (version 2) | String |
/images)Demonstrates image model capabilities, multimodality, and image generation/analysis.
| Method | Endpoint | Description | Response Type |
|---|---|---|---|
| GET | /images/find/{object} | Find and return image containing the specified object | byte[] (PNG) |
| GET | /images/generate/{object} | Generate a new image containing the specified object | byte[] (PNG) |
| GET | /images/describe | Describe all images (static + dynamically generated) | String[] |
| GET | /images/describe/{image} | Describe items in a specific image and categorize them | List<Item> |
| GET | /images/load | Load image descriptions into vector store for similarity search | void |
| GET | /images/generate-and-match/{object} | Generate image with object and find similar images in vector store | List<Document> |
/api)Demonstrates dynamic API generation with chat memory for any entity type.
| Method | Endpoint | Description | Response Type |
|---|---|---|---|
| GET/POST | /api/{entity} | Generate a dynamic list of any entity type with random values | String |
| GET/POST | /api/{entity}/{id} | Find and return specific entity by ID from current list | String |
# Generate a list of persons
curl http://localhost:8080/persons
# Calculate wallet value with AI tools
curl http://localhost:8080/wallet/with-tools
# Load stock data into vector store
curl http://localhost:8080/stocks/load-data
# Find stock with most growth
curl http://localhost:8080/stocks/v2/most-growth-trend
# Generate an image with cats
curl http://localhost:8080/images/generate/cats --output cats.png
# Generate dynamic list of cars
curl http://localhost:8080/api/cars
/wallet/* and /stocks/* endpoints/stocks/*, /images/load, /images/generate-and-match/*)/images/generate/* and /images/generate-and-match/* endpoints28 followers · starred Dec 2025
Java
100.0%