如何用初始数据填充Web应用程序 [英] How to populate web application with initial data

查看:107
本文介绍了如何用初始数据填充Web应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写Web应用程序,并且想知道建议的填充原始数据的方法是什么.这是JPA/Hibernate和Spring应用程序,由maven构建.到目前为止,我已经使用脚本将手工数据填充到数据库中,并填充了初始数据.
单元测试使用它们自己的数据,这些数据在每次测试之前通过代码创建.我的测试类扩展了 org.springframework.test.jpa.AbstractJpaTests .
最后,我想进行一个Maven构建,该构建将创建数据库表单实体(现在我需要先运行应用程序以创建数据库,然后运行脚本),然后填充初始/词典数据并运行单元测试和集成测试.此过程应完全自动化,以将其构建到CI服务器(哈德森)中,从头开始创建新数据库也是值得的.

I am writing web application and am wondering what the recommended way is to populate initial data. This is JPA/Hibernate and Spring application and is built by maven. Up to now I've used script wich populate database with initial data, started by hand.
Unit tests work with theirs own data, created in code before each test. My test classes extends org.springframework.test.jpa.AbstractJpaTests.
Finally I'd like to have a maven build which create database form entities (now I need to run application first time to create database, then run script) then populates initial/dictionary data and run unit and integration tests. This process should be fully automated to put this build in CI server (hudson), crating new database from scratch is also appreciate.


附加要求:数据库不可知的解决方案将是最有价值的.


Additional requirement: Database agnostic solution will be most valuable.

编辑:我正在寻找的最佳示例是

Best example of what I'm looking for is init closure in BootStrap.groovy.

推荐答案

编辑:在博客文章中添加了一个链接,该链接显示了如何使用Spring和DbUnit测试Hibernate JPA.

EDIT: Added a link to a blog post showing how to test Hibernate JPA with Spring and DbUnit.

[...]我想拥有一个从实体创建数据库的Maven构建

[...] I'd like to have a maven build which create database from entities

有一个 maven hibernate3插件,其中带有 hibernate3:hbm2ddl 目标可能会有所帮助.结合 maven sql插件,应该可以从生成的DDL.

There is a maven hibernate3 plugin with an hibernate3:hbm2ddl goal that might help. Coupled with the maven sql plugin, it should be possible to create this schema from the generated DDL.

[...]然后填充初始/词典数据

[...] then populates initial/dictionary data

同样, maven sql插件可以在这里完成这项工作.也许使用 DBUnit ,这是另一个不错的解决方案(请参见

Again, the maven sql plugin could do the job here. Or maybe with DBUnit which is another elegant solution (see the maven dbunit plugin).

并运行单元测试和集成测试.

and run unit and integration tests.

好吧,我不确定您的单元测试应该访问数据库,但是对于集成测试,请检查 DBUnit 使用Spring& DbUnit 是一个很好的例子.

Well, I'm not sure your unit tests should access the database but, for integrations tests, check DBUnit as I said. It's really a very nice tool that allows you to setup up the database in a known state, test tables for expected content after a test execution and put the database back in the initial state. See Testing JPA Hibernate with Spring & DbUnit for a nice example.

此过程应完全自动化,以将其构建到CI服务器(哈德森)中,从头开始创建新数据库也将受到赞赏.

This process should be fully automated to put this build in CI server (hudson), crating new database from scratch is also appreciate.

我认为这是可行的.

这篇关于如何用初始数据填充Web应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆