Spring H2 Support: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 27: Line 27:


Follow the JPA programming model described at [[Spring_Data_JPA#Adding_Persistence_to_an_Application_with_Spring_Data_JPA|Adding Persistence with Spring Data JPA]].
Follow the JPA programming model described at [[Spring_Data_JPA#Adding_Persistence_to_an_Application_with_Spring_Data_JPA|Adding Persistence with Spring Data JPA]].
To test from command line, add command-line support as specified in [[Console_Application_with_Spring_Boot|Console (command-line) Application with Spring Boot]].


=Spring Configuration=
=Spring Configuration=

Revision as of 17:36, 31 October 2018

Internal

Playground Example

Playground Spring Data H2 JPA

Overview

Simple Project

Use Spring Initializr to bootstrap the project. Alternatively use Spring Initializr-generated build.gradle and settings.gradle.

To bootstrap JPA and H2, add the following dependencies:

dependencies {
    ...
    implementation('org.springframework.boot:spring-boot-starter-data-jpa')
    runtimeOnly('com.h2database:h2')
    ...
}

Follow the JPA programming model described at Adding Persistence with Spring Data JPA.

To test from command line, add command-line support as specified in Console (command-line) Application with Spring Boot.

Spring Configuration

Add in application.properties or equivalent:

spring.datasource.url=jdbc:h2:tcp://localhost/mem:default
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.platform=h2

spring.datasource.initialization-mode=always
spring.jpa.hibernate.ddl-auto=none
spring.jpa.show-sql=true

SpringBoot DevTools H2 Console

SpringBoot DevTools H2 Console