During local DAO tests or unit tests, the db environment is sometimes difficult to implement, and even if the database environment is called, sometimes it does not want to add useless data to the db, spring provides a virtual db environment to facilitate unit testing without interfering with the real db environment.
Configure in spring environment:
<Jdbc: embedded-database id = "db_product_recommend" type = "H2">
<Jdbc: script. location = "classpath: databases/product-recommend-schema. SQL"/>
<Jdbc: script. location = "classpath: databases/product-recommend-data. SQL"/>
</Jdbc: embedded-database>
Type supports HSQL, H2, and Derby. The default value is HSQL.
The schema. SQL file is the statement used to create a database and data. SQL is the table data file. You can insert some data first.
After configuring the embedded database, you can inject it into the DAO that requires dataSource, and then you can perform the DAO unit test.
In addition, there is a code method to create an embedded database:
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder ();
EmbeddedDatabase db = builder. type (H2). script ("schema. SQL"). script ("test-data. SQL"). build ();
// Do stuff against the db (EmbeddedDatabase extends javax. SQL. DataSource)
Db. shutdown ();
Use Spring annotations to implement Netty server-side UDP applications
Spring2.5.6 + Hibernate3 + RMI Integration
Steps for integrating Struts2 and Spring