Spring bean创建时出现奇怪的lambda错误

时间:2015-12-01 13:07:53

标签: spring lambda java-8 wildfly

我首先道歉,因为我不知道在哪里提出这个问题,Wildfly,Spring,JDK还是?

我使用一些lambda表达式

通过spring java config初始化一些spring bean
@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();
}

但它会出现以下错误

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

我们使用的是Wildfly 9.0.2服务器+ Spring 4.2.3 + Postgres + JDK 8u30 + Linux

完整的堆栈跟踪

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)

1 个答案:

答案 0 :(得分:2)

通过更新到java 8更新66来修复它,使用的是java 8 u30