我有一个带有几个实体类的Spring Boot应用程序,我正试图使用flyway实现数据库迁移。似乎在启动时,Spring Boot根本没有运行flyway。
以下是我的application.properties
spring.datasource.url= jdbc:postgresql://localhost:5555/mfidb
spring.datasource.username=postgres
spring.datasource.password=postgres
spring.jpa.hibernate.ddl-auto=validate
spring.flyway.enabled=true
以下是我的build.gradle中与flyway有关的几行字。
plugins {
id 'org.springframework.boot' version '2.2.6.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
id "org.flywaydb.flyway" version "6.4.1"
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.flywaydb:flyway-core'
runtime('org.postgresql:postgresql:42.2.12')
}
flyway {
url = 'jdbc:postgresql://localhost:5555/mfidb'
user = 'postgres'
password = 'postgres'
}
我可以通过输入以下信息来运行我的迁移。gradle flywayMigrate -i
终端中。
但我希望迁移在启动时运行。
任何帮助都将是非常感激的,先谢谢你。
EDIT:
这是运行应用程序时的控制台输出
2020-05-05 11:55:59.022 INFO 50754 --- [ main] com.ubm.mfi.MfiApplication : Starting MfiApplication on MacBook-Pro.local with PID 50754 (~/Downloads/mfi 5/build/classes/java/main started by will in ~/Downloads/mfi 5)
2020-05-05 11:55:59.024 INFO 50754 --- [ main] com.ubm.mfi.MfiApplication : No active profile set, falling back to default profiles: default
2020-05-05 11:55:59.457 INFO 50754 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2020-05-05 11:55:59.495 INFO 50754 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 33ms. Found 2 JPA repository interfaces.
2020-05-05 11:55:59.778 INFO 50754 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2020-05-05 11:55:59.783 INFO 50754 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-05-05 11:55:59.784 INFO 50754 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.33]
2020-05-05 11:55:59.838 INFO 50754 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-05-05 11:55:59.838 INFO 50754 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 768 ms
2020-05-05 11:55:59.917 INFO 50754 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2020-05-05 11:55:59.944 INFO 50754 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.4.12.Final
2020-05-05 11:55:59.991 INFO 50754 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2020-05-05 11:56:00.051 INFO 50754 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2020-05-05 11:56:00.114 INFO 50754 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2020-05-05 11:56:00.124 INFO 50754 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL10Dialect
2020-05-05 11:56:00.545 INFO 50754 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2020-05-05 11:56:00.548 INFO 50754 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2020-05-05 11:56:00.818 WARN 50754 --- [ main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2020-05-05 11:56:00.891 INFO 50754 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2020-05-05 11:56:01.005 INFO 50754 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2020-05-05 11:56:01.007 INFO 50754 --- [ main] com.ubm.mfi.MfiApplication : Started MfiApplication in 2.255 seconds (JVM running for 2.983)
这里是数据迁移的路径。
添加 logging.level.root=debug
你的 application.properties
文件,以便在启动应用程序时查看详细信息。
也只需将flyway用户和密码添加到 application.properties
.
spring.flyway.url = 'jdbc:postgresql://localhost:5555/mfidb'
spring.flyway.password=postgres
spring.flyway.user=postgres
如果你不需要从gradle中运行flyway,你可以从以下地方删除flyway配置。build.gradle
你的application.properties在我看来很完美。
我也在使用Flyway,它工作得很好,并且在我的应用程序启动时执行迁移。我的应用程序中唯一的条目是 build.gradle
与flyway相关的是依赖性
runtime("org.flywaydb:flyway-core")
我觉得你应该把所有其他与航道有关的条目从 build.gradle
.
当我进行gradle clean build时,我的依赖关系没有被刷新,所以flyway源码从来没有出现过。我不得不在IDE中手动刷新我的依赖关系,然后它就开始工作了。当你在这么简单的事情上花了好几个小时的时间时,我很难过。Giga关于改变日志级别的评论帮助我找到了问题所在。谢谢你