Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Flyway 5.x and Spring Boot 2.x #10

Closed
SingleShot opened this issue Jul 19, 2018 · 7 comments
Closed

Support Flyway 5.x and Spring Boot 2.x #10

SingleShot opened this issue Jul 19, 2018 · 7 comments
Assignees
Labels
status: invalid An issue that we don't feel is valid

Comments

@SingleShot
Copy link

SingleShot commented Jul 19, 2018

We are currently upgrading to Spring Boot 2, which uses Flyway 5. It would be great if this tool could support Flyway 5 as well. My workaround of course is to stay on Flyway 4.2.0 but it would be nice to upgrade.

@tomix26
Copy link
Collaborator

tomix26 commented Jul 20, 2018

Hi, what version of embedded database do you use? Because since version 1.3.0, Spring Boot 2 and Flyway 5 should be supported. Here is a demo project that uses them and works well.

@tomix26 tomix26 added the status: waiting-for-feedback We need additional information before we can continue label Jul 20, 2018
@SingleShot
Copy link
Author

SingleShot commented Jul 20, 2018

I was on 1.2.0. I looked in mvnrepository.com for the latest version and saw 1.2.0 is the latest for embedded-database-spring-test-core so figured that's the latest - I see embedded-database-spring-test is at 1.3.0. After your question I played around a bit and now my tests are working great.

I'm not sure if this is expected or not, but I have to list the following two dependencies or my tests won't run on Flyway 4.x:

<dependency>
    <groupId>io.zonky.test</groupId>
    <artifactId>embedded-database-spring-test</artifactId>
    <version>1.3.0</version>
</dependency>

<dependency>
    <groupId>io.zonky.test</groupId>
    <artifactId>embedded-database-spring-test-core</artifactId>
    <version>1.2.0</version>
</dependency>

Omitting embedded-database-spring-test-core leads to this:

Caused by: java.lang.ClassNotFoundException: io.zonky.test.db.postgres.EmbeddedPostgresContextCustomizerFactory

Putting it back, Flyway 4.x works. However, I still cannot run tests with Flyway 5.x. I receive this when running the tests:

java.lang.IllegalStateException: Failed to load ApplicationContext

	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
	at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)
	at io.zonky.test.db.flyway.OptimizedFlywayTestExecutionListener.optimizedDbReset(OptimizedFlywayTestExecutionListener.java:131)
	at io.zonky.test.db.flyway.OptimizedFlywayTestExecutionListener.beforeTestClass(OptimizedFlywayTestExecutionListener.java:92)
	at org.springframework.test.context.TestContextManager.beforeTestClass(TestContextManager.java:195)
	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:60)
	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Error when initializing the data source
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:296)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
	at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1081)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:856)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
	at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:120)
	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98)
	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116)
	... 13 more
Caused by: java.lang.IllegalStateException: Error when initializing the data source
	at com.google.common.base.Preconditions.checkState(Preconditions.java:459)
	at io.zonky.test.db.flyway.DefaultFlywayDataSourceContext.getTarget(DefaultFlywayDataSourceContext.java:94)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:192)
	at com.sun.proxy.$Proxy121.getConnection(Unknown Source)
	at org.flywaydb.core.internal.util.jdbc.JdbcUtils.openConnection(JdbcUtils.java:51)
	at org.flywaydb.core.internal.database.DatabaseFactory.createDatabase(DatabaseFactory.java:67)
	at org.flywaydb.core.Flyway.execute(Flyway.java:1634)
	at org.flywaydb.core.Flyway.migrate(Flyway.java:1168)
	at org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer.afterPropertiesSet(FlywayMigrationInitializer.java:66)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)
	... 30 more

@SingleShot
Copy link
Author

It's possible I am having some dependency issues with my Spring Boot 2 upgrade. I shall report back ;)

@tomix26
Copy link
Collaborator

tomix26 commented Jul 20, 2018

The previous embedded-database-spring-test-core maven artifact was the same as embedded-database-spring-test artifact but with excluded auto-configuration. The same result is newly achieved by this:

<dependency>
    <groupId>io.zonky.test</groupId>
    <artifactId>embedded-database-spring-test</artifactId>
    <version>1.3.0</version>
    <scope>test</scope>
    <exclusions>
        <exclusion>
            <groupId>io.zonky.test</groupId>
            <artifactId>embedded-database-spring-test-autoconfigure</artifactId>
        </exclusion>
    </exclusions>
</dependency>

It is described in the documentation: https://github.com/zonkyio/embedded-database-spring-test#disabling-auto-configuration

So there is no need to use the embedded-database-spring-test-core artifact at all. And that's why Flyway 5 does not work for you. Because the stack trace you have attached comes from the older embedded-database-spring-test-core:1.2.0 artifact and not from the newer embedded-database-spring-test:1.3.0 in which the support for Flyway 5 was added.

@tomix26
Copy link
Collaborator

tomix26 commented Jul 20, 2018

The ClassNotFoundException is strange, because the class is definitely part of embedded-database-spring-test:1.3.0 artifact. Try to clean up your local maven repository, maybe it will help.

@SingleShot
Copy link
Author

SingleShot commented Jul 24, 2018

Oops. Forgot to report back. My issues were indeed caused by transitive dependency messiness in my upgrade to Spring Boot 2. All is working, and in the manner documented in the project README. Please close this ticket as "Won't Fix: Reporter is an Idiot" 😛

Thanks again for making this tool available and supporting it!

@tomix26
Copy link
Collaborator

tomix26 commented Jul 25, 2018

Thanks for the feedback. I'm glad everything is working fine. 🙂

@tomix26 tomix26 added status: invalid An issue that we don't feel is valid and removed status: waiting-for-feedback We need additional information before we can continue labels Jul 25, 2018
@tomix26 tomix26 self-assigned this Jul 25, 2018
@tomix26 tomix26 closed this as completed Jul 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

2 participants