我正在构建一个使用h2
数据库的应用程序,我的persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="taskUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>com.github.tarrsalah.jersey.todo.app.model.Task</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:h2:file:/home/tarrsalah/src/github.com/tarrsalah/jaxrs-todo-app/target/todo"/>
<property name="javax.persistence.jdbc.user" value=""/>
<property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/>
<property name="javax.persistence.jdbc.password" value=""/>
</properties>
</persistence-unit>
</persistence>
如您所见,我在javax.persistence.jdbc.url
属性中有一个指向本地h2
数据库的硬链接,我想在 github 上共享我的代码。
如何在不更改persistence.xml
配置文件的情况下使代码的克隆版本正常工作?
(PS:我正在使用 flyway 进行数据库迁移)
要与他人共享此代码,您可以尝试使用内存中的 h2 数据库
<property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:test;DB_CLOSE_DELAY=1000"/>