如何在H2数据库中持久化数据 [英] How to persist data in H2 database

查看:285
本文介绍了如何在H2数据库中持久化数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序有 3 个组件,

My application has 3 components,

1) 一个面向用户的组件,接收请求并存储到数据库中2) 一个后端组件,它从数据库中读取数据,对其进行处理并将其发送到外部系统.3) 一个存储用户输入的数据库

1) A user facing component that receives requests and stores into the DB 2) A backend component that reads data form the DB, processes it and sends it on to an external system. 3) A DB that stores user input

我目前正在 eclipse 中使用 H2 在内存数据库(不是基于文件的)中进行测试.我想端到端测试,但问题是我已经停止面向用户的组件并启动后端组件.因此,每次启动后端组件时,都会从头开始创建数据库.

I am currently testing using H2 in memory database (NOT file based) from eclipse. I want to test end to end, but the problem is I have stop the user facing component and start the backend component. So, the DB gets created from scratch each time I start the backend component.

如何进行测试,使流程是这样的:用户输入数据 -> 数据持久化到 DB -> Baackend 连接到相同的持久化数据 -> 处理数据 + 传递给外部系统?

How do I test so that the flow is like this: user enters data -> data persisted into DB -> Baackend connects to the same persisted data -> processes data + passes to external system?

注意:我尝试使用 ddl-auto: update,但它不起作用.

NOTE: I tried using ddl-auto: update, but it doesn't work.

推荐答案

除了spring.jpa.hibernate.ddl-auto=update,设置auto_reconnect为true.

示例:

spring.datasource.url=jdbc:h2:file:~/test2;DB_CLOSE_ON_EXIT=FALSE;AUTO_RECONNECT=TRUE
spring.datasource.driver-class-name=org.h2.Driver

这篇关于如何在H2数据库中持久化数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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