从application.properties用于Spring引导的数据库application.yml [英] Database application.yml for Spring boot from applications.properties
问题描述
我有一个工作正常的Spring Boot应用程序,该应用程序连接到Postgres数据库.我已经用application.properties文件设置了项目,但想切换到application.yml文件.但是,当我进行切换时,我的应用程序在尝试连接到数据库时出错.
I've got a working Spring Boot Application that connects to a Postgres database. I've got the project set up with an application.properties file, but would like to make the switch over to an application.yml file. However when I make the switch, my application errors out while attempting to connect to the db.
原始的applications.properties文件:
Original applications.properties file:
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文件中得到的内容:
And Here's what I've got so far in the application.yml file:
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
我在文件类型之间的转换中缺少某些内容吗?
Am I missing something in the translation between file types?
推荐答案
您需要将属性名称中的每个.
字符视为yaml
文件中的级别:
You need to treat each .
character in property names as levels in the yaml
file:
spring:
jpa:
database: POSTGRESQL
show-sql: true
hibernate:
ddl-auto: create-drop
datasource:
platform: postgres
url: jdbc:postgresql://localhost:5432/mydb
username: foo
password: bar
driverClassName: org.postgresql.Driver
编辑:已建议进行修改,非常感谢. driverClassName
属性实际上应该在spring.datasource
下.但是,此答案的目的是显示如何将properties
文件转换为yaml
格式.因此,我将driverClassName
属性更改为正确的路径,这不是从properties
到yaml
转换的一部分.
EDIT: edits have been suggested, thanks for that. The driverClassName
property actually should be under spring.datasource
. However, the purpose of this answer was to show how a properties
file is converted into yaml
format. So I have changed the driverClassName
property to be at the right path, that is not part of the transformation from properties
to yaml
.
这篇关于从application.properties用于Spring引导的数据库application.yml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!