Class BeanFactoryProvider

  • All Implemented Interfaces:
    Closeable, AutoCloseable, javax.inject.Provider<org.springframework.beans.factory.config.ConfigurableListableBeanFactory>

    public class BeanFactoryProvider
    extends Object
    implements javax.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 Detail

      • 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)
      • get

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