【发布时间】:2021-02-16 07:21:09
【问题描述】:
我的 Spring 框架有问题。它不会在启动时自动创建数据库。我阅读了HowTo-Guides of Spring on how to initialize the database 并按照这些步骤操作,但它不起作用。我也在网上搜索了类似的问题,但没有找到任何可以帮助我的东西。
错误说明:
在服务器启动时,我收到一条错误消息:
FATAL: Datenbank »money_man_api_db« existiert nicht(德语)
FATAL: Database »money_man_api_db« does not exist(英文翻译)
我的配置:
application.properties:
server.port=3000
# Basic Connection Configuration
spring.datasource.hikari.connection-timeout=20000
spring.datasource.hikari.maximum-pool-size=5
# PostgreSQL Configuration
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=create
spring.datasource.initialization-mode=always
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/money_man_api_db
spring.datasource.username=postgres
spring.datasource.password=admin
为什么没有初始化数据库?我是不是忘记了什么?
【问题讨论】:
-
Springboot 不会为您自动创建数据库。您需要自己创建数据库。但是 Springboot 可以在 DB 中自动创建表。你已经拥有了这个属性:spring.jpa.hibernate.ddl-auto.
-
在这种情况下,HowTo-Guide 的标题确实具有误导性,感谢您的回答。
标签: java spring postgresql spring-boot kotlin