首页 > 解决方案 > 如何在 spring.datasource.url 中使用 2 个默认值

问题描述

spring
  datasource:
    url: ${DB_HOST_URI:#{jdbc:postgresql://localhost:5433}}/${PS_DB_NAME:#{ps_application}}

您好,我有上面的代码,当我尝试运行 ./gradlew bootRun 时,默认的 url 应该jdbc:postgresql://localhost:5433/ps_application是不正确的,我收到:

14:10:28[main][ERROR]o.s.b.SpringApplication:: Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Invocation of init method failed; nested exception is org.flywaydb.core.internal.exception.FlywaySqlException: 
Unable to obtain connection from database: The connection attempt failed.

您是否知道如何拆分 URL 并最终使用具有默认值的两个变量?或对此有任何想法?

我正在使用spring boot和gradle提前谢谢!

标签: javaspringpostgresqlspring-boot

解决方案


推荐阅读