Class BeanFactoryProvider

java.lang.Object
org.springframework.guice.module.BeanFactoryProvider
All Implemented Interfaces:
jakarta.inject.Provider<org.springframework.beans.factory.config.ConfigurableListableBeanFactory>, Closeable, AutoCloseable

public class BeanFactoryProvider extends Object implements jakarta.inject.Provider<org.springframework.beans.factory.config.ConfigurableListableBeanFactory>, Closeable

A Provider for a BeanFactory from an ApplicationContext that will not be refreshed until the Guice injector wants to resolve dependencies. Delaying the refresh means that the bean factory can resolve dependencies from Guice modules (and vice versa).

Also implements Closeable so if you want to clean up resources used in the application context then you can keep a reference to the provider and call close() on it when the application is shut down. Alternatively, you could register an ApplicationContextInitializer that sets a shutdown hook, so that the context is closed automatically when the JVM ends.

Author:
Dave Syer
  • Method Details

    • from

      public static BeanFactoryProvider from(String... basePackages)
      Create an application context by scanning these base packages.
      Parameters:
      basePackages - base packages to scan
      Returns:
      a provider
    • from

      public static BeanFactoryProvider from(Class<?>... config)
      Create an application context using these configuration classes.
      Parameters:
      config - classes to build an application
      Returns:
      a provider
    • initializer

      public BeanFactoryProvider initializer(org.springframework.context.ApplicationContextInitializer<org.springframework.context.ConfigurableApplicationContext>... initializers)
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • get

      public org.springframework.beans.factory.config.ConfigurableListableBeanFactory get()
      Specified by:
      get in interface jakarta.inject.Provider<org.springframework.beans.factory.config.ConfigurableListableBeanFactory>