Flyway无法在Java Spring中设置架构?

时间:2019-07-01 13:28:39

标签: java spring flyway

我的问题是,即使检测到迁移文件,并且无法从cmd运行相同的迁移文件,我也无法从flyway java spring进行迁移。

我已经尝试设置我在Internet上找到的所有可能有用的参数来配置模式,但是它仍然停留在“ PUBLIC”上

首先,问题如下:(来自Java spring的日志)

"2019-07-01 15:06:04.296  INFO 296 --- [           main] o.f.core.internal.command.DbMigrate      : Current version of schema "PUBLIC": << Empty Schema >>
2019-07-01 15:06:04.297  INFO 296 --- [           main] o.f.core.internal.command.DbMigrate      : Migrating schema "PUBLIC" to version 1 - Create person table
2019-07-01 15:06:04.324  INFO 296 --- [           main] o.f.core.internal.command.DbMigrate      : Migrating schema "PUBLIC" to version 2 - Add people
2019-07-01 15:06:04.339  INFO 296 --- [           main] o.f.core.internal.command.DbMigrate      : Migrating schema "PUBLIC" to version 3 - Add people2
2019-07-01 15:06:04.356  INFO 296 --- [           main] o.f.core.internal.command.DbMigrate      : Successfully applied 3 migrations to schema "PUBLIC" (execution time 00:00.094s)"

该表称为 public ,我也无法从mysql工作台上看到它。

但是,如果我从命令行使用flyway migration进行操作,它将更改名为 td 的架构,这是我的意图:

"Migrating schema `td` to version 1 - Create person table
Migrating schema `td` to version 2 - Add people
Successfully applied 2 migrations to schema `td` (execution time 00:00.207s)"

Java的flyway配置:

public static void main(String[] args) {
    Flyway flyway = new Flyway();
    flyway.setBaselineOnMigrate(true);
    flyway.migrate();
    SpringApplication.run(TimeReportApplication.class, args);
}

application.properties:

flyway.user=root
flyway.password=root
flyway.url=jdbc:mysql://localhost:3306/td
flyway.schemas=TD

命令行的有效飞行通道配置:

flyway.url=jdbc:mysql://localhost:3306/td
flyway.user=root
flyway.password=root

您有什么建议可能会出问题吗?

1 个答案:

答案 0 :(得分:0)

因此,经过一天的尝试,我找到了解决方案:

  1. 您必须将“数据源”添加到初始化文件。这将由Spring从application.properties文件自动配置,您必须将其放置在src / main / resources中:

    公共类TimeReportApplication {

    @Autowired
    static DataSource dataSource;
    
    public static void main(String[] args) {
        PrintLog.print("Server started");
        System.out.println("Server started");
        Flyway flyway = new Flyway();
        flyway.clean();
        flyway.setDataSource(dataSource);
        flyway.setSqlMigrationPrefix("V");
        flyway.setBaselineOnMigrate(true);
        flyway.migrate();
        SpringApplication.run(TimeReportApplication.class, args);
    }
    

    }

  2. 在application.properties文件中,在每个参数“ spring”之前写入,例如: spring.flyway.user = root