0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

H2データ永続化手順

Posted at

H2Database永続化

Spring Bootの学習に際して、煩わしかったのでまとめます。

H2をただ導入するだけだと実行されるたびにデータが初期化されてしまいます。

H2のデータを永続化かつ、データをコンソールで操作できるにしていきます。

o/demo/src/main/resources/application.properties
	
	spring.application.name=demo
	
+	spring.sql.init.mode=never 
+	spring.h2.console.enabled=true
+	spring.jpa.hibernate.ddl-auto=update
+	spring.datasource.url=jdbc:h2:./data/db
+	spring.datasource.driver-class-name=org.h2.Driver
+	spring.datasource.username=sa
+	spring.datasource.password=password
+	spring.jpa.database-platform=org.hibernate.dialect.H2Dialect

ルートディレクトリにdataというディレクトリが作成され、そこにデータが保存されます。

これで完了です。

以下URLでコンソールにもログイン可能です。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?