在没有Spring Boot的情况下设置内存H2数据库 [英] Setting up in-memory H2 database without Spring Boot

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

问题描述

我正在从事Spring 5(非Sprig Boot)项目.我需要使用内存中的H2数据库测试我的应用程序.我在Maven构建工具上将Spring与Java Config一起使用.有什么方法可以配置内存中的H2 DB?

I am working in a spring 5 (Not Sprig Boot) project. I need to test my application with in-memory H2 database. I am using Spring with Java Config on maven build tool. Is there any way I can configure in-memory H2 DB?

推荐答案

通常,我在@Config类中使用它:

Usually I use this in my @Config class:

@Bean
public DataSource h2TestDataSource(){
   return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2).build();
}

所以我在spring项目中使用Spring Embedded DB(我不使用spring boot)

So I use Spring Embedded DB in my spring projects (I don't use spring boot)

我希望它有用.

这篇关于在没有Spring Boot的情况下设置内存H2数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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