Building AI-Powered Applications with Vertex AI and Spring Boot

Emrah Önder
3 min readSep 18, 2024

You know the story — AI is on the rise, and almost everyone wants to use it!

There’s even an AI-powered toothbrush, and I sincerely hope we never see AI-powered toilet paper! 😄

yes, this is generated by ChatGPT!

Anyway, let’s jump to our topic. Generally, Python is the go-to language for accessing or developing AI-related projects. However, for simple services like Vertex AI, you don’t need to learn Python at all. You can use the power of Java and Spring Boot!

Nowadays, I am playing with this kind of service like Vertex AI (a.k.a. Gemini) and I could not find a simple example that shows access to Vertex AI from SpringBoot so decided to create it myself.

To interact with Vertex AI, you can send HTTP requests to its endpoints, but instead, I chose the super handy library Langchain4j

Dependencies

First, you’ll need to add the necessary dependencies. The first one is required for all services, while the second one, langchain4j-vertex-ai-gemini, is specific to Vertex AI:

<dependency>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j</artifactId>
<version>0.31.0</version>
</dependency>
<dependency>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j-vertex-ai-gemini</artifactId>…

--

--