【问题标题】:Spring Boot and Liquibase: migrations not being executed when initiating the serverSpring Boot 和 Liquibase:启动服务器时未执行迁移
【发布时间】:2021-02-12 20:57:49
【问题描述】:

我使用 Liquibase 和 MongoDB 运行迁移的微服务在服务器启动时不会执行迁移,正如 Spring Boot 所声称的那样。

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <dependency>
        <groupId>org.liquibase</groupId>
        <artifactId>liquibase-core</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-mongodb</artifactId>
    </dependency>
    <dependency>
        <groupId>org.liquibase.ext</groupId>
        <artifactId>liquibase-mongodb</artifactId>
        <version>4.1.1</version>
    </dependency>
</dependencies>
spring:
  application:
    name: photo-app-liquibase
  datasource:
    driver-class-name: liquibase.ext.mongodb.database.MongoClientDriver
    url: mongodb://localhost:27017/photo-app
  liquibase:
    change-log: classpath:db/changelog/db.changelog-master.xml

迁移和主文件位于src/main/resources/db/changelog文件夹中

<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
    xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
    http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">

    <!-- Tried without "db/changelog" and appending "./" before already -->
    <include file="db/changelog/20201029215628_create-users-table.xml"/>
</databaseChangeLog>

但是在启动服务器时,没有运行迁移的迹象,数据库中也没有任何变化。

2020-10-30 08:32:04.928  INFO 12065 --- [           main] c.g.p.PhotoAppLiquibaseApplication       : Starting PhotoAppLiquibaseApplication on gabriel with PID 12065 (/home/gabriel/Workspace/spring/spring-microservices-ii/photo-app-liquibase/target/classes started by gabriel in /home/gabriel/Workspace/spring/spring-microservices-ii/photo-app-discovery-service)
2020-10-30 08:32:04.933  INFO 12065 --- [           main] c.g.p.PhotoAppLiquibaseApplication       : No active profile set, falling back to default profiles: default
2020-10-30 08:32:05.559  INFO 12065 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data MongoDB repositories in DEFAULT mode.
2020-10-30 08:32:05.582  INFO 12065 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 14ms. Found 0 MongoDB repository interfaces.
2020-10-30 08:32:05.864  INFO 12065 --- [           main] org.mongodb.driver.cluster               : Cluster created with settings {hosts=[localhost:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms'}
2020-10-30 08:32:05.920  INFO 12065 --- [localhost:27017] org.mongodb.driver.connection            : Opened connection [connectionId{localValue:1, serverValue:22}] to localhost:27017
2020-10-30 08:32:05.928  INFO 12065 --- [localhost:27017] org.mongodb.driver.cluster               : Monitor thread successfully connected to server with description ServerDescription{address=localhost:27017, type=STANDALONE, state=CONNECTED, ok=true, minWireVersion=0, maxWireVersion=8, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=4278944}
2020-10-30 08:32:06.134  INFO 12065 --- [           main] c.g.p.PhotoAppLiquibaseApplication       : Started PhotoAppLiquibaseApplication in 1.729 seconds (JVM running for 2.57)

Process finished with exit code 0

【问题讨论】:

标签: spring mongodb spring-boot liquibase


【解决方案1】:

Liquibase 不支持 MongoDB,但它们提供了一个扩展来支持 MongoDB: => How to use Liquibase-MongoDb-Spring-boot

【讨论】:

    猜你喜欢
    • 2017-06-17
    • 1970-01-01
    • 2020-08-20
    • 2018-09-07
    • 2018-10-05
    • 2021-08-03
    • 2016-06-15
    • 2016-10-09
    • 2020-12-25
    相关资源
    最近更新 更多