This sample demonstrates how to use Genkit with Spring Boot to create a web server that exposes AI flows as REST endpoints.
- Java 21 or later
- Maven 3.x
- (Optional) Google GenAI API key for AI-powered flows
-
From the project root directory, build all modules:
mvn clean install
-
Run the sample:
cd samples/spring ./run.shOr manually:
mvn compile exec:java
-
The server will start on
http://localhost:8080
curl http://localhost:8080/healthResponse:
{"status":"ok"}curl http://localhost:8080/api/flowsResponse:
{"flows":["greet","reverse","info"]}curl -X POST http://localhost:8080/api/flows/greet \
-H "Content-Type: application/json" \
-d '"World"'Response:
"Hello, World!"curl -X POST http://localhost:8080/api/flows/reverse \
-H "Content-Type: application/json" \
-d '"Hello Spring"'Response:
"gnirpS olleH"curl -X POST http://localhost:8080/api/flows/info \
-H "Content-Type: application/json" \
-d '"genkit"'Response:
{"topic":"genkit","timestamp":1703420000000,"version":"1.0.0"}The sample uses the following configuration:
SpringPluginOptions.builder()
.port(8080) // HTTP port
.host("0.0.0.0") // Bind to all interfaces
.basePath("/api/flows") // Base path for flow endpoints
.build()This sample is functionally equivalent to the Jetty sample but uses Spring Boot instead. The main differences are:
| Aspect | Spring Plugin | Jetty Plugin |
|---|---|---|
| Framework | Spring Boot 3.x | Eclipse Jetty 12 |
| Startup | Full Spring context | Lightweight server |
| Configuration | Spring properties | Builder pattern |
| Ecosystem | Spring Boot starters | Standalone |
Choose Spring Boot when you need:
- Integration with other Spring components
- Spring Security for authentication
- Spring Data for database access
- Production-ready features (actuator, metrics)
Choose Jetty when you need:
- Minimal dependencies
- Faster startup time
- Simple deployment
Apache License 2.0