项目作者: mayank1989gupta

项目描述 :
Demo for Spring Boot and H2 DB integration
高级语言: Java
项目地址: git://github.com/mayank1989gupta/SpringBootH2DB.git
创建时间: 2019-02-19T12:33:34Z
项目社区:https://github.com/mayank1989gupta/SpringBootH2DB

开源协议:

下载


Spring Boot App with H2 DB

  1. H2 is an open-source lightweight Java database. It can be embedded in Java applications or run in
  2. the client-server mode. Generally used for POC's,as it is embedded DB, hence it is not used for
  3. production env.

To enable the UI console for H2 DB

  1. spring.h2.console.enabled=true
  2. URL: http://<IP>:<port>/h2-console
  3. JDBC URL: jdbc:h2:mem:testdb

Defining the schema and set up data

  1. The schema and set up/initial data could be defined with the help
  2. of sql files in the resources folder.
  3. Samples added: schema.sql &, data.sql

To check the above

  1. Implement the run() method from CommandLineRunner in the main boot class:
  2. @Override
  3. public void run(String ...args) throws Exception {
  4. LOGGER.log(Level.INFO, () -> "Student id 10001 -> {}" + repository.findById(10001L));
  5. }
  6. Output: Student id 10001 -> {}Student [id=10001, name=ABC XYZ, passport=E1234567]
  7. Sample data created during start from the SQL files.

Build and Run

  1. clean: gradle clean
  2. build: gradle build
  3. run app: gradle bootrun