mongodb 的新 jhipster 应用程序集成测试期间出现异常

Exception during integration test in new jhipster app with mongodb

当我创建新的 jhipster 应用程序和 运行 集成测试时,我遇到了这样的异常:

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.mongodb.Mongo]: Factory method 'mongo' threw exception; nested exception is de.flapdoodle.embed.process.exceptions.DistributionException: java.io.EOFException: Unexpected end of ZLIB input stream
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    ... 147 common frames omitted
Caused by: de.flapdoodle.embed.process.exceptions.DistributionException: java.io.EOFException: Unexpected end of ZLIB input stream
    at de.flapdoodle.embed.process.runtime.Starter.prepare(Starter.java:65) ~[de.flapdoodle.embed.process-1.40.0.jar:na]
    at cz.jirutka.spring.embedmongo.EmbeddedMongoBuilder.build(EmbeddedMongoBuilder.java:99) ~[embedmongo-spring-1.3.0.jar:1.3.0]
    at pl.myapp.config.MongoConfiguration.mongo(MongoConfiguration.java:23) ~[test-classes/:na]
    at pl.myapp.config.MongoConfiguration$$EnhancerBySpringCGLIB$$c24baf13.CGLIB$mongo[=11=](<generated>) ~[spring-core-4.1.6.RELEASE.jar:na]
    at pl.myapp.config.MongoConfiguration$$EnhancerBySpringCGLIB$$c24baf13$$FastClassBySpringCGLIB$$fb7c7abc.invoke(<generated>) ~[spring-core-4.1.6.RELEASE.jar:na]
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:309) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at pl.myapp.config.MongoConfiguration$$EnhancerBySpringCGLIB$$c24baf13.mongo(<generated>) ~[spring-core-4.1.6.RELEASE.jar:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_25]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_25]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_25]
    at java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0_25]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    ... 148 common frames omitted

您的 JAR 文件似乎已损坏,您是否尝试删除 Maven 存储库并重新安装这些库?

解决方案是更改 mongo spring bean 使用的 EmbeddedMongoBuilder 中的版本:

    @Bean
public Mongo mongo() throws IOException {
    System.setProperty("DB.TRACE","true");
    return new EmbeddedMongoBuilder()
            .version("2.6.10")
            .bindIp("127.0.0.1")
            .port(allocateRandomPort())
            .build();
}