Package org.springframework.jdbc.datasource.init

# Class DataSourceInitializer

java.lang.Object
org.springframework.jdbc.datasource.init.DataSourceInitializer

All Implemented Interfaces:
  `org.springframework.beans.factory.DisposableBean`, `org.springframework.beans.factory.InitializingBean`

public class DataSourceInitializer extends Object implements org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.DisposableBean
Used to set up a database during initialization and `clean up` a database during destruction.

Since:
  3.0
Author:
  Dave Syer, Sam Brannen
See Also:
  - `DatabasePopulator`

## Constructor Summary

Constructors
Constructor
Description
`DataSourceInitializer()`

## Method Summary

Modifier and Type
Method
Description
`void`
`afterPropertiesSet()`
Use the database populator to set up the database.
`void`
`destroy()`
Use the database cleaner to clean up the database.
`void`
`setDatabaseCleaner(DatabasePopulator databaseCleaner)`
Set the `DatabasePopulator` to execute during the bean destruction phase, if any, cleaning up the database and leaving it in a known state for others.
`void`
`setDatabasePopulator(DatabasePopulator databasePopulator)`
Set the `DatabasePopulator` to execute during the bean initialization phase, if any.
`void`
`setDataSource(DataSource dataSource)`
The `DataSource` for the database to populate when this component is initialized and to clean up when this component is shut down.
`void`
`setEnabled(boolean enabled)`
Flag to explicitly enable or disable the database populator and database cleaner.

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

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

## Constructor Details

### DataSourceInitializer

public DataSourceInitializer()

## Method Details

### setDataSource

public void setDataSource(DataSource dataSource)
The `DataSource` for the database to populate when this component is initialized and to clean up when this component is shut down.

This property is mandatory with no default provided.

Parameters:
  `dataSource` - the DataSource

### setDatabasePopulator

public void setDatabasePopulator(@Nullable DatabasePopulator databasePopulator)
Set the `DatabasePopulator` to execute during the bean initialization phase, if any.

Parameters:
  `databasePopulator` - the `DatabasePopulator` to use during initialization
See Also:
  - `setDatabaseCleaner(org.springframework.jdbc.datasource.init.DatabasePopulator)`

### setDatabaseCleaner

public void setDatabaseCleaner(@Nullable DatabasePopulator databaseCleaner)
Set the `DatabasePopulator` to execute during the bean destruction phase, if any, cleaning up the database and leaving it in a known state for others.

Parameters:
  `databaseCleaner` - the `DatabasePopulator` to use during destruction
See Also:
  - `setDatabasePopulator(org.springframework.jdbc.datasource.init.DatabasePopulator)`

### setEnabled

public void setEnabled(boolean enabled)
Flag to explicitly enable or disable the database populator and database cleaner.

Parameters:
  `enabled` - `true` if the database populator and database cleaner should be called on startup and shutdown, respectively

### afterPropertiesSet

public void afterPropertiesSet()
Use the database populator to set up the database.

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

### destroy

public void destroy()
Use the database cleaner to clean up the database.

Specified by:
  `destroy` in interface `org.springframework.beans.factory.DisposableBean`