Class SpringPlugin

java.lang.Object
com.google.genkit.plugins.spring.SpringPlugin
All Implemented Interfaces:
Plugin, ServerPlugin

public class SpringPlugin extends Object implements 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 Details

    • SpringPlugin

      public SpringPlugin()
      Creates a SpringPlugin with default options.
    • SpringPlugin

      public SpringPlugin(SpringPluginOptions options)
      Creates a SpringPlugin with the specified options.
      Parameters:
      options - the plugin options
  • Method Details

    • create

      public static SpringPlugin create(int port)
      Creates a SpringPlugin with the specified port.
      Parameters:
      port - the HTTP port
      Returns:
      a new SpringPlugin
    • getName

      public String getName()
      Description copied from interface: Plugin
      Returns the unique identifier for the plugin. This name is used for registration and lookup.
      Specified by:
      getName in interface Plugin
      Returns:
      the plugin name
    • init

      public List<Action<?,?,?>> init()
      Description copied from interface: Plugin
      Initializes the plugin. This method is called once during Genkit initialization. The plugin should return a list of actions that it provides.
      Specified by:
      init in interface Plugin
      Returns:
      list of actions provided by this plugin
    • init

      public List<Action<?,?,?>> init(Registry registry)
      Description copied from interface: Plugin
      Initializes 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).

      Specified by:
      init in interface Plugin
      Parameters:
      registry - the Genkit registry for resolving dependencies
      Returns:
      list of actions provided by this plugin
    • start

      public void start() throws Exception
      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:
      start in interface ServerPlugin
      Throws:
      Exception - if the server cannot be started or if interrupted while waiting
    • stop

      public void stop() throws Exception
      Stops the Spring Boot server.
      Specified by:
      stop in interface ServerPlugin
      Throws:
      Exception - if the server cannot be stopped
    • getPort

      public int getPort()
      Returns the port the server is listening on.
      Specified by:
      getPort in interface ServerPlugin
      Returns:
      the configured port
    • isRunning

      public boolean isRunning()
      Returns true if the server is currently running.
      Specified by:
      isRunning in interface ServerPlugin
      Returns:
      true if the server is running, false otherwise