Package com.google.genkit.plugins.spring
Class SpringPlugin
java.lang.Object
com.google.genkit.plugins.spring.SpringPlugin
- All Implemented Interfaces:
Plugin,ServerPlugin
SpringPlugin provides HTTP endpoints for Genkit flows using Spring Boot.
This plugin exposes registered flows as HTTP endpoints, making it easy to deploy Genkit applications as web services using Spring Boot.
Example usage:
Genkit genkit = Genkit.builder().plugin(new SpringPlugin(SpringPluginOptions.builder().port(8080).build())).build();
// Define your flows...
// Start the server and block (keeps application running)
genkit.start();
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a SpringPlugin with default options.SpringPlugin(SpringPluginOptions options) Creates a SpringPlugin with the specified options. -
Method Summary
Modifier and TypeMethodDescriptionstatic SpringPlugincreate(int port) Creates a SpringPlugin with the specified port.getName()Returns the unique identifier for the plugin.intgetPort()Returns the port the server is listening on.init()Initializes the plugin.Initializes the plugin with access to the registry.booleanReturns true if the server is currently running.voidstart()Starts the Spring Boot server and blocks until it is stopped.voidstop()Stops the Spring Boot server.
-
Constructor Details
-
SpringPlugin
public SpringPlugin()Creates a SpringPlugin with default options. -
SpringPlugin
Creates a SpringPlugin with the specified options.- Parameters:
options- the plugin options
-
-
Method Details
-
create
Creates a SpringPlugin with the specified port.- Parameters:
port- the HTTP port- Returns:
- a new SpringPlugin
-
getName
Description copied from interface:PluginReturns the unique identifier for the plugin. This name is used for registration and lookup. -
init
Description copied from interface:PluginInitializes the plugin. This method is called once during Genkit initialization. The plugin should return a list of actions that it provides. -
init
Description copied from interface:PluginInitializes the plugin with access to the registry. This method is called once during Genkit initialization. The plugin should return a list of actions that it provides.Override this method instead of
Plugin.init()when your plugin needs to resolve dependencies from the registry (e.g., embedders, models). -
start
Starts the Spring Boot server and blocks until it is stopped.This is the recommended way to start the server in a main() method. Similar to Express's app.listen() in JavaScript, this method will keep your application running until the server is explicitly stopped.
Example usage:
SpringPlugin spring = new SpringPlugin(SpringPluginOptions.builder().port(8080).build()); Genkit genkit = Genkit.builder().plugin(spring).build(); // Define your flows... // Start and block spring.start();- Specified by:
startin interfaceServerPlugin- Throws:
Exception- if the server cannot be started or if interrupted while waiting
-
stop
Stops the Spring Boot server.- Specified by:
stopin interfaceServerPlugin- Throws:
Exception- if the server cannot be stopped
-
getPort
public int getPort()Returns the port the server is listening on.- Specified by:
getPortin interfaceServerPlugin- Returns:
- the configured port
-
isRunning
public boolean isRunning()Returns true if the server is currently running.- Specified by:
isRunningin interfaceServerPlugin- Returns:
- true if the server is running, false otherwise
-