我有一个连接到 Postgres 数据库的工作 Spring Boot 应用程序。我已经使用 application.properties 文件设置了项目,但想切换到 application.yml 文件。但是,当我进行切换时,我的应用程序在尝试连接到数据库时出错。
原始 applications.properties 文件:
spring.jpa.database=POSTGRESQL
spring.datasource.platform=postgres
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=create-drop
spring.database.driverClassName=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/mydb
spring.datasource.username=foo
spring.datasource.password=bar
到目前为止,这是我在 application.yml 文件中得到的内容:
spring.jpa:
database: POSTGRESQL
hibernate.ddl-auto: create-drop
show-sql: true
spring.datasource:
platform: postgres
driverClassName: org.postgresql.Driver
url: jdbc:postgresql://localhost:5432/mydb
username: foo
password: bar
我在文件类型之间的翻译中遗漏了什么吗?
原文由 user3051261 发布,翻译遵循 CC BY-SA 4.0 许可协议
您需要将属性名称中的每个
.
字符视为yaml
文件中的级别:编辑:已建议进行编辑,谢谢。
driverClassName
属性实际上应该在spring.datasource
之下。但是,此答案的目的是显示properties
文件如何转换为yaml
格式。因此,我已将driverClassName
属性更改为正确的路径,这不是从properties
到yaml
转换的一部分。