-
Notifications
You must be signed in to change notification settings - Fork 19
spring dbunit servlet module
excilys edited this page Aug 12, 2011
·
11 revisions
This module provides a ServletContextListener for loading and unloading DBUnit DataSets on web application startup and shutdown.
For example, this can be useful when developing a prototype where database content needs to be refreshed periodically.
Declare the Listener in your web.xml
<listener>
<listener-class>com.excilys.ebi.spring.dbunit.servlet.DataLoaderListener</listener-class>
</listener>
In this case, the engine will load a file named dataSet.xml located at the classpath root.
Defaults can be overridden thanks to context params in the web.xml :
<context-param>
<!-- the DataSet files, comma separated -->
<param-name>spring.dbunit.dataSets</param-name>
<param-value>classpath:dataSet.xml</param-value>
</context-param>
<context-param>
<!-- Operation to be performed on webapp startup (see DBOps enum) -->
<param-name>spring.dbunit.setUpOperation</param-name>
<param-value>CLEAN_INSERT</param-value>
</context-param>
<context-param>
<!-- Operation to be performed on webapp shutdown (see DBOps enum) -->
<param-name>spring.dbunit.tearDownOperation</param-name>
<param-value>NONE</param-value>
</context-param>
<context-param>
<!-- File format (see DataSetFormat enum) -->
<param-name>spring.dbunit.format</param-name>
<param-value>FLAT</param-value>
</context-param>
<context-param>
<!-- Database type (see DBType enum) -->
<param-name>spring.dbunit.dbType</param-name>
<param-value>HSQLDB</param-value>
</context-param>
<context-param>
<!-- Name of DataSource spring bean in case of multiple DataSources in the ApplicationContext -->
<param-name>spring.dbunit.SPRING_DBUNIT_INIT_PARAM_PREFIX</param-name>
<param-value></param-value>
</context-param>
One can specify multiple DataSet locations. In this case, corresponding DataSets will be played in reverse order during shutdown phase so that they'll behave nicely if they depend on each other.