我的问题是,即使检测到迁移文件,并且相同的迁移文件可以从 cmd 运行,我也无法从 Flyway java Spring 执行迁移。
我已经尝试设置我在互联网上找到的所有可能有用的参数来配置架构,但它仍然停留在“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 migrate 从命令行执行此操作,它会更改名为 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);
}
应用程序属性:
flyway.user=root
flyway.password=root
flyway.url=jdbc:mysql://localhost:3306/td
flyway.schemas=TD
命令行的工作flyway配置:
flyway.url=jdbc:mysql://localhost:3306/td
flyway.user=root
flyway.password=root
您对可能出现的问题有什么建议吗?
最佳答案
经过一天的尝试,我找到了解决方案:
您必须将“数据源”添加到初始化文件中。这将由 Spring 从您的 application.properties 文件自动配置,您必须将其放置在 src/main/resources 中:
公共(public)类 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); }
}
在 application.properties 文件中的每个参数“spring”之前写入,例如: spring.flyway.user=root
关于java - Flyway无法在java spring中设置模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56836570/