Git Product home page Git Product logo

Comments (7)

tomix26 avatar tomix26 commented on September 1, 2024

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.

from embedded-database-spring-test.

SingleShot avatar SingleShot commented on September 1, 2024

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

from embedded-database-spring-test.

SingleShot avatar SingleShot commented on September 1, 2024

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

from embedded-database-spring-test.

tomix26 avatar tomix26 commented on September 1, 2024

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.

from embedded-database-spring-test.

tomix26 avatar tomix26 commented on September 1, 2024

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.

from embedded-database-spring-test.

SingleShot avatar SingleShot commented on September 1, 2024

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!

from embedded-database-spring-test.

tomix26 avatar tomix26 commented on September 1, 2024

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

from embedded-database-spring-test.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.