使用Spring启动和设置内存数据库 [英] Start and setup in-memory DB using Spring

查看:246
本文介绍了使用Spring启动和设置内存数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Spring编写一个小型演示应用程序,使用Spring,需要访问数据库。它应该在不同的机器上运行,并且设置真正的数据库将是太多的努力。因此,我想使用一个嵌入的。

I'm writing a small demo application in Java using Spring, that needs to have access to a database. It should run on different machines and it would be far too much effort to setup a real database. Therefore I want to use an embedded one.

DB有一个给定的模式(两个表)和一些(很少)预定义的条目。我正在寻找一个简单的方法来启动一个内存数据库,创建表和填充数据。所有这一切都应该在初始化Spring上下文时发生。

The DB has a given schema (two tables) and some (very few) pre-defined entries. I'm looking for a simple way to start an in-memory database, create the tables and fill in the data. All of this should happen while initializing the Spring context.

我的方法是使用H2作为我的数据库,然后可能是Spring Batch从csv-或xml加载数据文件。然而,我希望有一个更容易的方法来实现这一点。有没有可以做这个开箱即用的任何数据库/框架/工具?

My approach would be to use H2 as my database and then maybe Spring Batch to load the data from csv- or xml-files. However I was hoping there might be an easier way to achieve this. Are there any databases/frameworks/tools that can do this out-of-the-box?

它只需要几个SQL命令来设置一切需要。我正在寻找一种方法来在Spring环境中做到这一点尽可能简单。

It would only take a few SQL-commands to set-up everything I need. I'm looking for a way to do this in a Spring-environment as simple as possible.

推荐答案

在嵌入式数据库支持中,请参阅嵌入式数据库在文档中支持

Spring has some built-in embedded database support, see embedded database support in the documentation.

这篇关于使用Spring启动和设置内存数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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