Spring-boot: flyway location to root subfolder

Created on 16 May 2018  路  9Comments  路  Source: spring-projects/spring-boot

I placed migration files in root of project and there is no way to point to that folder.
Before migration to spring boot 2 working path was:
flyway.locations=filesystem:./in_root_folder
now, nothing works
spring.flyway.locations=classpath:/../../../in_root_folder spring.flyway.locations=filesystem:./in_root_folder spring.flyway.locations=filesystem:/../../../in_root_folder

invalid

Most helpful comment

Thanks @wilkinsona

db.migrations

works in my old project
but I solved the problem by create a folder named flyway
and add config in property

spring.flyway.locations=classpath:flyway

All 9 comments

How have you identified that "nothing works"? If there's an error, is it produced by Spring Boot or by Flyway? Can you please provide a small sample application (either as a GitHub repository or as a zip attached to this issue) that works with Boot 1.5 and fails when upgraded to Boot 2.0?

I ve been just migrating spring boot from 1.5 to 2.0 and nothing more and as migration guide tells I changed deprecated
flyway.locations > spring.flyway.locations:
so from
flyway.locations: filesystem:./x-db/sql/model
to
spring.flyway.locations: filesystem:./x-db/sql/model
and it is not working anymore. Error:
Caused by: java.lang.IllegalStateException: Cannot find migrations location in: [filesystem:./x-db/sql/model] (please add migrations or check your Flyway configuration)
This error occurs while running flyway in tests

Thanks but, unfortunately, we don't have time to piece something together from a brief description. Even if we did have time, there's still a risk that we'll end up with something different that either doesn't reproduce the problem or fails in a different way. If you'd like us to spend some time investigating, please spend some time to provide a complete sample that reproduces the behaviour you have described either in a GitHub repository in a zip attached to this issue.

@wilkinsona https://github.com/poppinlr/springboot_flyway_issue.git
here is my template project to show the issue

I do put the sql file in classpath:db/migration
but still got error :

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flyway' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.flywaydb.core.Flyway]: Factory method 'flyway' threw exception; nested exception is java.lang.IllegalStateException: Cannot find migrations location in: [classpath:db/migration] (please add migrations or check your Flyway configuration)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:587) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1254) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1103) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:541) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:501) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:304) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1089) ~[spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:859) ~[spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.1.0.BUILD-20180517.000531-99.jar:2.1.0.BUILD-SNAPSHOT]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) [spring-boot-2.1.0.BUILD-20180517.000531-99.jar:2.1.0.BUILD-SNAPSHOT]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395) [spring-boot-2.1.0.BUILD-20180517.000531-99.jar:2.1.0.BUILD-SNAPSHOT]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) [spring-boot-2.1.0.BUILD-20180517.000531-99.jar:2.1.0.BUILD-SNAPSHOT]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1255) [spring-boot-2.1.0.BUILD-20180517.000531-99.jar:2.1.0.BUILD-SNAPSHOT]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1243) [spring-boot-2.1.0.BUILD-20180517.000531-99.jar:2.1.0.BUILD-SNAPSHOT]
    at com.example.demo.DemoApplication.main(DemoApplication.java:10) [classes/:na]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.flywaydb.core.Flyway]: Factory method 'flyway' threw exception; nested exception is java.lang.IllegalStateException: Cannot find migrations location in: [classpath:db/migration] (please add migrations or check your Flyway configuration)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:579) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
    ... 20 common frames omitted
Caused by: java.lang.IllegalStateException: Cannot find migrations location in: [classpath:db/migration] (please add migrations or check your Flyway configuration)
    at org.springframework.util.Assert.state(Assert.java:94) ~[spring-core-5.0.6.RELEASE.jar:5.0.6.RELEASE]
    at org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration.checkLocationExists(FlywayAutoConfiguration.java:168) ~[spring-boot-autoconfigure-2.1.0.BUILD-20180517.000446-99.jar:2.1.0.BUILD-SNAPSHOT]
    at org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration.flyway(FlywayAutoConfiguration.java:152) ~[spring-boot-autoconfigure-2.1.0.BUILD-20180517.000446-99.jar:2.1.0.BUILD-SNAPSHOT]
    at org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration$$EnhancerBySpringCGLIB$$cacddfba.CGLIB$flyway$0(<generated>) ~[spring-boot-autoconfigure-2.1.0.BUILD-20180517.000446-99.jar:2.1.0.BUILD-SNAPSHOT]
    at org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration$$EnhancerBySpringCGLIB$$cacddfba$$FastClassBySpringCGLIB$$1da927be.invoke(<generated>) ~[spring-boot-autoconfigure-2.1.0.BUILD-20180517.000446-99.jar:2.1.0.BUILD-SNAPSHOT]
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-5.0.6.RELEASE.jar:5.0.6.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:361) ~[spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE]
    at org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration$$EnhancerBySpringCGLIB$$cacddfba.flyway(<generated>) ~[spring-boot-autoconfigure-2.1.0.BUILD-20180517.000446-99.jar:2.1.0.BUILD-SNAPSHOT]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_161]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_161]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_161]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_161]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]

Thanks for the sample.

Your migrations are in the wrong directory. They are in a directory named src/main/resources/db.migrations. They need to be in a directory named src/main/resources/db/migrations. Note the / rather than the . between db and migrations.

I can't see any usage of a property with a value beginning with filesystem: like you mentioned in your original description of the problem. Does this sample reproduce the exact problem you're seeing?

Thanks @wilkinsona

db.migrations

works in my old project
but I solved the problem by create a folder named flyway
and add config in property

spring.flyway.locations=classpath:flyway

I'm pleased to hear you've solved your problem. Thanks for letting us know.

@poppinlr
but you placed folder flyway in root of project?
I want to admit that I don't want to place sql files in src/main/resources I want them in root directory of project

This path below is worked for me: in application.yml

check-location: true
locations:
- classpath:./db/migration

./db dot is needed in here.

Was this page helpful?
0 / 5 - 0 ratings