如何在 Spring Boot 配置中显式传递数据库名称?

use*_*373 5 postgresql configuration spring datasource spring-boot

我有一个 Spring Boot 应用程序,它连接到 Postgres 数据库。我已在 application.properties 中将数据源 url 指定为 -

spring.datasource.url=jdbc:postgresql://<这里的服务器IP>:5432/mydb

jdbc url (jdbc:postgresql://< server ip here >:5432/) 实际上存储在我的应用程序能够读取的单独的外部位置中。因此,我只想在属性文件中指定数据库名称。

我不想将数据库名称作为某些环境变量传递,因为它不会改变。

我已经被困在这一点上很长一段时间了,我怎样才能实现同样的目标?

Vik*_*ini 2

将其添加到您的 application.properties 文件中

spring.jpa.hibernate.ddl-auto=create\update\none
spring.datasource.url=jdbc:postgresql://host:port/db
spring.datasource.username=username
spring.datasource.password=password
Run Code Online (Sandbox Code Playgroud)