2

First of my apologies, since i don't know where to raise this issue, Wildfly, Spring, JDK or ?

I have some spring bean initializing via spring java config as follows using some lambda expression,

@Bean
@DependsOn("dataSource")
public Flyway applyMigration(final DataSource dataSource) {

    tenants().parallelStream().forEach(schema -> {
        final Flyway flyway = new Flyway();
        flyway.setBaselineOnMigrate(true);
        flyway.setOutOfOrder(true);
        flyway.setDataSource(dataSource);
        flyway.setSchemas(schema);
        flyway.migrate();
    });

    return new Flyway();
}

but it gives the following error

Caused by: java.lang.invoke.LambdaConversionException: 
Type mismatch in captured lambda parameter 0: 
expecting interface javax.sql.DataSource, found interface javax.sql.DataSource

we are using Wildfly 9.0.2 server + Spring 4.2.3 + Postgres + JDK 8u30 + Linux

Full stacktrace follows

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flyway' defined in com.mycomp.config.persistence.migration.DBMigrationConfiguration: 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.BootstrapMethodError: call site initialization exception
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    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.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findDefaultEntityManagerFactory(PersistenceAnnotationBeanPostProcessor.java:575)
    at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findEntityManagerFactory(PersistenceAnnotationBeanPostProcessor.java:541)
    at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.resolveEntityManager(PersistenceAnnotationBeanPostProcessor.java:707)
    at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.getResourceToInject(PersistenceAnnotationBeanPostProcessor.java:680)
    at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:169)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
    at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessPropertyValues(PersistenceAnnotationBeanPostProcessor.java:354)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.flywaydb.core.Flyway]: Factory method 'flyway' threw exception; nested exception is java.lang.BootstrapMethodError: call site initialization exception
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
Caused by: java.lang.BootstrapMethodError: call site initialization exception
    at java.lang.invoke.CallSite.makeSite(CallSite.java:328)
    at java.lang.invoke.MethodHandleNatives.linkCallSite(MethodHandleNatives.java:296)
    at com.mycomp.config.persistence.migration.DBMigrationConfiguration.applyMigration(DBMigrationConfiguration.java:76)
    at com.mycomp.config.persistence.migration.DBMigrationConfiguration.flyway(DBMigrationConfiguration.java:70)
    at com.mycomp.config.persistence.migration.DBMigrationConfiguration$$EnhancerBySpringCGLIB$$1a6b7996.CGLIB$flyway$1(<generated>)
    at com.mycomp.config.persistence.migration.DBMigrationConfiguration$$EnhancerBySpringCGLIB$$1a6b7996$$FastClassBySpringCGLIB$$b29fa4c.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:318)
    at com.mycomp.config.persistence.migration.DBMigrationConfiguration$$EnhancerBySpringCGLIB$$1a6b7996.flyway(<generated>)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
Caused by: java.lang.invoke.LambdaConversionException: Type mismatch in captured lambda parameter 0: expecting interface javax.sql.DataSource, found interface javax.sql.DataSource
    at java.lang.invoke.AbstractValidatingLambdaMetafactory.validateMetafactoryArgs(AbstractValidatingLambdaMetafactory.java:256)
    at java.lang.invoke.LambdaMetafactory.metafactory(LambdaMetafactory.java:303)
    at java.lang.invoke.CallSite.makeSite(CallSite.java:289)
Sreekanth
  • 539
  • 1
  • 7
  • 24
  • Have you tried it without lambdas? – jny Dec 01 '15 at 14:16
  • 1
    Whenever you encounter a reported type mismatch of two identical names, someone is messing around with `ClassLoader`s. In a sane setup, the interface `javax.sql.DataSource` should always get resolved via the bootstrap loader as it’s a standard JFC API class. Setups failing to do so are asking for trouble… – Holger Dec 01 '15 at 15:35
  • According to the stacktrace, the problem occurs inside a method `applyMigration`, invoked by `flyway`. But according to the code you have posted, `flyway` doesn’t ever invoke `applyMigration`… – Holger Dec 01 '15 at 15:49
  • Yes thats true, i just changed the method signature but forget to update the same here. Just updated here. I can think of wildfly, because wildfly have its unique way of modular class loading, where postgres is one among them. – Sreekanth Dec 02 '15 at 05:29
  • @jny yes i have tried without lambda and its working fine. – Sreekanth Dec 02 '15 at 05:39

1 Answers1

2

Got it fixed by updating to java 8 update 66, were using java 8 u30

Sreekanth
  • 539
  • 1
  • 7
  • 24