Class EmbeddedDatabaseFactoryBean

java.lang.Object
org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseFactory
org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseFactoryBean
All Implemented Interfaces:
org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.FactoryBean<DataSource>, org.springframework.beans.factory.InitializingBean

public class EmbeddedDatabaseFactoryBean extends EmbeddedDatabaseFactory implements org.springframework.beans.factory.FactoryBean<DataSource>, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.DisposableBean
A subclass of EmbeddedDatabaseFactory that implements FactoryBean for registration as a Spring bean. Returns the actual DataSource that provides connectivity to the embedded database to Spring.

The target DataSource is returned instead of an EmbeddedDatabase proxy since the FactoryBean will manage the initialization and destruction lifecycle of the embedded database instance.

Implements DisposableBean to shut down the embedded database when the managing Spring container is being closed.

Since:
3.0
Author:
Keith Donald, Juergen Hoeller
  • Constructor Details

    • EmbeddedDatabaseFactoryBean

      public EmbeddedDatabaseFactoryBean()
  • Method Details

    • setDatabaseCleaner

      public void setDatabaseCleaner(DatabasePopulator databaseCleaner)
      Set a script execution to be run in the bean destruction callback, cleaning up the database and leaving it in a known state for others.
      Parameters:
      databaseCleaner - the database script executor to run on destroy
      See Also:
    • afterPropertiesSet

      public void afterPropertiesSet()
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
    • getObject

      public @Nullable DataSource getObject()
      Specified by:
      getObject in interface org.springframework.beans.factory.FactoryBean<DataSource>
    • getObjectType

      public Class<? extends DataSource> getObjectType()
      Specified by:
      getObjectType in interface org.springframework.beans.factory.FactoryBean<DataSource>
    • isSingleton

      public boolean isSingleton()
      Specified by:
      isSingleton in interface org.springframework.beans.factory.FactoryBean<DataSource>
    • destroy

      public void destroy()
      Specified by:
      destroy in interface org.springframework.beans.factory.DisposableBean