无法在 Spring Boot 中将 Flyway 迁移与 postgresQL 连接起来

Posted

技术标签:

【中文标题】无法在 Spring Boot 中将 Flyway 迁移与 postgresQL 连接起来【英文标题】:Not able connect flyway migration with postgresSQL in spring boot 【发布时间】:2020-03-14 16:05:30 【问题描述】:

我正在使用PostgreSQLspring-boot 项目设置flyway 迁移,但无法连接数据库并出现异常。

未能执行目标 org.flywaydb:flyway-maven-plugin:6.0.8:migrate (default-cli) on project open-feign: org.flywaydb.core.api.FlywayException: Unable to connect to数据库。配置url、用户和密码! -> [帮助 1]

Spring boot 版本: 2.2.1.RELEASE

Maven:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
    <groupId>org.flywaydb</groupId>
    <artifactId>flyway-core</artifactId>
    <version>6.0.8</version>
</dependency>

<dependency>
    <groupId>org.postgresql</groupId>
    <artifactId>postgresql</artifactId>
    <scope>runtime</scope>
</dependency>

<plugin>
    <groupId>org.flywaydb</groupId>
    <artifactId>flyway-maven-plugin</artifactId>
    <version>6.0.8</version>
</plugin>

application.yml


    spring:
      application:
        name: MIGRATE DEMO
      datasource:
        url: jdbc:postgresql://localhost:5432/DABASENAME
        driver-class-name: org.postgresql.Driver
        username: postgres
        password: root
        platform: postgres
        dbcp2:
          validation-query: SELECT 1
      jpa:
        datbase: POSTGRESQL
        database-platform: org.hibernate.dialect.PostgreSQL9Dialect
        show-sql: true
        generate-ddl: true
        properties:
          hibernate.jdbc.lob.non_contextual_creation: true
        hibernate:
          ddl-auto: validate

    flyway:
      user: postgres
      password: root
      schemas: DABASENAME
      url: jdbc:postgresql://localhost:5432/DABASENAME
      locations: filesystem:db/migration

提前致谢

【问题讨论】:

您可以删除flyway插件以及flyway依赖的版本,然后您也可以删除flyway配置。 Spring Boot 将完成剩下的工作 @SimonMartinelli 感谢您的回复,我尝试了同样的错误。 org.flywaydb.core.api.FlywayException:无法连接到数据库。配置url、用户和密码! 你能发布堆栈跟踪吗? [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1.319 s [INFO] Finished at: 2019-11-19T16:15:39+05:30 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.flywaydb:flyway-maven-plugin:6.0.8:migrate (default-cli) on project migrate-demo: org.flywaydb.core.api.FlywayException: Unable to connect to the database. Configure the url, user and password! -&gt; [Help 1] 【参考方案1】:

终于可以正常工作了,下面是我所做的更改。

根据 FlywayAutoConfiguration spring.flyway 期望例如

spring.flyway: 

无法读取如下属性

spring: 
    flyway: 
        user: ....

版本格式Vx.x__(description) [V(capital letter) 1.2(integer)__(two underscore characters)]

【讨论】:

以上是关于无法在 Spring Boot 中将 Flyway 迁移与 postgresQL 连接起来的主要内容,如果未能解决你的问题,请参考以下文章

无法将docker Spring-Boot应用程序与docker-compose中的mysql容器和flyway连接起来

具有 JPA 依赖关系的 Flyway Spring Boot Autowired Bean

Spring Boot gradle flyway - 验证错误 - 模式验证:缺少表

带有PostgreSQL,Flyway和Hikari的Spring Boot 2:驱动程序声称不接受jdbcUrl

Flyway 和 Spring Boot 集成

Flyway 在 Spring Boot 上不工作时如何调试?