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



我用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

Liquibase不支持MongoDB,但它们提供了支持MongoDB的扩展:=>如何使用Liquibase MongoDb Spring引导

最新更新