How to debug when Flyway is not working on Spring Boot?

I use Maven and Spring Boot. I am running the application using mvn spring-boot:run .

https://flywaydb.org/documentation/plugins/springboot says that Flyway should be called when Spring starts.

So my pom.xml contains a dependency on Flyway.

 <dependency> <groupId>org.flywaydb</groupId> <artifactId>flyway-core</artifactId> <version>4.1.2</version> </dependency> 

The first time I ran the Maven team on it, I downloaded the Flyway stuff, so I think the dependency works.

I have the following files:

 ./src/main/resources/db/migration/V123__foo.sql ./src/main/resources/application.properties 

The above article implies that it should "work", but I don’t understand where it will find the JDBC URL for the database. Therefore, I added the following to the application.properties file:

 flyway.url=jdbc:postgresql://localhost:5432/services?user=postgres&password=postgres flyway.enabled=true 

When Spring Launches Download (and downloads and accesses my web application), Flyway has no logs. I think Flyway is ignored.

What can I do? Or, more generally, how would I debug this problem myself?

+7
spring-boot flyway
source share
1 answer

No one sent a response, so I will post what I found out.

M. In his comments on the Deinum question, he was really right, the problem was the lack of a data source.

My initial question was what should be the approach for debugging this problem. Obviously, one option is to publish to stackoverflow :) But I would like to know how to do it myself.

Spring Boot has several classes that look at your code and class path and act accordingly. For example, there are classes that enforce rules, such as "if Flyway is on the way and there is a data source, then run Flyway." This rule did not work in my case because I did not have a data source.

This is not the case when the code you write calls Spring Boot; on the contrary, Spring Boot (external to your code) checks your code and decides what to do based on the rules. This architecture is known as action at a distance . The main problem with action at a distance is very difficult to debug.

The only real way to find a solution, and that’s how I started checking the M. Deinum diagnostics, to read the Spring boot source code and understand the annotations that are used to create Spring Boot code,

From source code to Spring Boot Flyway integration, we see

 @ConditionalOnClass(Flyway.class) @ConditionalOnBean(DataSource.class) 

This means that "this code will be executed if Flyway is in the classpath, and if there is a DataSource bean available, otherwise it will work seamlessly."

So, the answer to the question "how to debug this problem" is that there is no mechanism other than reading the Spring Boot source code and figuring out how it works.

If you want to avoid such a problem, you need to avoid frameworks that work through the "action at a distance" and include Spring Boot.

+8
source share

All Articles