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

标签 spring postgresql spring-boot configuration datasource

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

spring.datasource.url=jdbc:postgresql://<服务器ip>:5432/mydb

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

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

我现在在这一点上停留了很长一段时间,我怎样才能达到同样的效果?

最佳答案

将此添加到您的 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

关于spring - 如何在 Spring Boot 配置中显式传递数据库名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50673762/

相关文章:

java - Jetty、Jersey 和 Spring 的 NoInitialContextException

spring - 为什么将 "org.springframework.security.crypto.password.PasswordEncoder"注入(inject) "DaoAuthenticationProvider"时会起作用?

java - Spring Boot通过 JDBC 语句执行 DDL 删除架构时出错

java - 保护 Spring Boot 中的根 URL

java - 如何强制tomcat重新加载以重置静态AtomicBoolean

node.js - "Negative"SQL (postgres) 查询

sql - PostgreSQL - 具有两个多对多关系的 SELECT

sql - 每 15 分钟高效地查询一个巨大的时间序列表一行

eclipse - "Unable to find main class"在 Eclipse 中的 spring-boot 项目中使用 Maven

spring-boot - 运行 Zuul Server 时禁用 Eureka Client