首页 文章

无法使用Flyway和Test Class构建Spring Boot项目

提问于
浏览
0

我已将flyway添加到我们的spring boot java应用程序中 . 我可以用maven成功构建项目的唯一方法是注释掉测试类 . 否则,当flyway遇到试图在Create Table脚本中创建索引的SQL脚本时,我会收到flyway错误 . 错误如下:引起:org.flywaydb.core.internal.dbsupport.FlywaySqlScriptException:消息:未知数据类型:“IDK_COMPANIES_CITY”; SQL语句:如何在不注释测试的情况下构建项目?测试类如下:注意:我可以注释掉Test类,成功构建和部署项目 . 所有SQL脚本都成功迁移 . 该应用程序在 Cloud 中使用MariaDB . 谢谢 .

package com.spring.sample;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = DatabaseTestApplication.class)
@WebAppConfiguration
public class DatabaseTestApplicationTests {

    @Test
    public void contextLoads() {
    }

}

1 回答

  • 1

    我假设您在测试中使用的是内存数据库,而不是连接到实时数据库 . 这可能意味着运行测试时创建的内存数据库不支持Flyway脚本中的语法 .

    尝试在测试应用程序属性中设置此项:

    spring.jpa.hibernate.dialect=org.hibernate.dialect.MySQLDialect
    

    我建议使用MySQLDialect的原因是MariaDB没有,因为它在_2743159中也是如此 .

    如果上述方法无效,请尝试使用此属性:

    spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect
    

相关问题