Spring Boot不会在H2中创建表-JPA / Hibernate

时间:2019-01-18 13:49:00

标签: spring hibernate spring-boot spring-data-jpa h2

我尝试按照本指南使用Spring Boot将数据存储在h2数据库中。 https://memorynotfound.com/spring-boot-spring-data-jpa-hibernate-h2-web-console

但是似乎未创建数据库表。它也没有收到错误消息,所以我不知道我在做什么错。

我尝试添加@EntityScan,但是它不起作用。

*更新

spring.h2.console.enabled=true
spring.h2.console.path=/console
spring.h2.console.settings.trace=false
spring.h2.console.settings.web-allow-others=false

spring.datasource.url=jdbc:h2:mem:example-app;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
spring.datasource.platform=h2
spring.datasource.username = sa
spring.datasource.password =
spring.datasource.driverClassName = org.h2.Driver
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect

spring.jpa.hibernate.ddl-auto = update
spring.jpa.properties.hibernate.show_sql=false
spring.jpa.properties.hibernate.use_sql_comments=false
spring.jpa.properties.hibernate.format_sql=false

1 个答案:

答案 0 :(得分:0)

确保您具有此config属性(尽管它自动类似于h2):

spring:
  jpa:
    hibernate:
      ddl-auto: update