首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Spring Boot和Liquibase:启动服务器时不执行迁移

Spring Boot和Liquibase:启动服务器时不执行迁移
EN

Stack Overflow用户
提问于 2020-10-30 19:39:13
回答 1查看 311关注 0票数 1

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

代码语言:javascript
运行
复制
<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>
代码语言:javascript
运行
复制
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文件夹中

代码语言:javascript
运行
复制
<?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>

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

代码语言:javascript
运行
复制
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
EN

回答 1

Stack Overflow用户

发布于 2021-07-16 17:30:22

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64607659

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档