Package org.springframework.jdbc.datasource.embedded

# 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

## Field Summary

### Fields inherited from class org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseFactory

`DEFAULT_DATABASE_NAME`

### Fields inherited from interface org.springframework.beans.factory.FactoryBean

`OBJECT_TYPE_ATTRIBUTE`

## Constructor Summary

Constructors
Constructor
Description
`EmbeddedDatabaseFactoryBean()`

## Method Summary

Modifier and Type
Method
Description
`void`
`afterPropertiesSet()`
`void`
`destroy()`
`DataSource`
`getObject()`
`Class<? extends DataSource>`
`getObjectType()`
`boolean`
`isSingleton()`
`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.

### Methods inherited from class org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseFactory

`getDatabase, getDataSource, initDatabase, setDatabaseConfigurer, setDatabaseName, setDatabasePopulator, setDatabaseType, setDataSourceFactory, setGenerateUniqueDatabaseName, shutdownDatabase`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## 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:
  - `EmbeddedDatabaseFactory.setDatabasePopulator(org.springframework.jdbc.datasource.init.DatabasePopulator)`
  - `DataSourceInitializer.setDatabaseCleaner(org.springframework.jdbc.datasource.init.DatabasePopulator)`

### afterPropertiesSet

public void afterPropertiesSet()

Specified by:
  `afterPropertiesSet` in interface `org.springframework.beans.factory.InitializingBean`

### getObject

@Nullable public 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`