Spring Boot + IntelliJ + Embedded Database = Headache

前端 未结 5 1648
执笔经年
执笔经年 2020-12-29 05:05

Either I\'m missing some core concept buried deep within some documentation (Spring, Spring Boot, H2, HSQLDB, Derby, IntelliJ) or I\'ve been staring at this for too long.

5条回答
  •  时光说笑
    2020-12-29 06:09

    To add to what heenenee mentioned above. If you dont specify AUTO_SERVER only one connection will be permitted to your H2 instance.

    I am using spring-boot with spring-data-jpa. Make sure you have @Entity declared for your entities that represent each table(s).

    Following is my application.yml / application.properties

    spring.datasource.url: 
    jdbc:h2:file:/Users/blah[![enter image description here][1]][1]/db/vlad4;AUTO_SERVER=TRUE
    spring.datasource.username: sa
    spring.datasource.password:
    
    spring:
      jpa:
        hibernate:
          ddl-auto: create #will create schema based on entities
        show-sql: true
    

    Start your application and import some data into it. Spring boot will automatically import your data if you have import.sql in the classpath ex: /src/main/resources/import.sql

    Configure you IntelliJ like so

    If you are not using IntelliJ download the server/client combo @ http://www.h2database.com/html/download.html extract it and start the browser-based client using:

    h2/bin: java -cp h2*.jar org.h2.tools.Server
    

    Connect to your imbedded database by specifying the connection string:

提交回复
热议问题