Jarle Hansen
Jarle Hansen

Reputation: 1993

Spring boot load H2 db file from classpath

I want to package prepopulated h2 db-files with a Spring boot application. The database is only going to be used to read values.

How am I able to load the H2 files that are available on the classpath? I am very uncertain how to setup the spring.datasource.url to get this to work.

Upvotes: 2

Views: 3110

Answers (1)

Miloš Milivojević
Miloš Milivojević

Reputation: 5369

I would suggest you export the schema and data into SQL scripts and use the in-memory H2 DB in combination with Spring Boot's built-in initialization feature: http://docs.spring.io/spring-boot/docs/current/reference/html/howto-database-initialization.html#howto-initialize-a-database-using-spring-jdbc

Granted, it may result in a slower startup if you have a relatively big dataset but if that were the case you probably wouldn't have put it in the JAR in the first place :)

Upvotes: 2

Related Questions