Spring Boot EmbeddedMongoAutoConfiguration抛出ArrayIndexOutOfBoundsException,无法初始化MongoTemplate bean

w46czmvw  于 2023-04-11  发布在  Spring
关注(0)|答案(1)|浏览(200)

我只是将MongoDB配置添加到现有的Sping Boot 应用程序中,一些测试类具有@SpringBootTest注解,这些类抛出异常,表明我需要定义嵌入式MongoDB版本,如下所示
...Set the spring.mongodb.embedded.version property...
我在test/resources/application.properties上将此设置为4.4版本。
现在它开始抛出下面的异常

[org/springframework/boot/autoconfigure/data/mongo/MongoDatabaseFactoryDependentConfiguration.class]: Unsatisfied dependency expressed through method 'mongoTemplate' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mongoDatabaseFactory' defined in class path resource 

[org/springframework/boot/autoconfigure/data/mongo/MongoDatabaseFactoryConfiguration.class]: Unsatisfied dependency expressed through method 'mongoDatabaseFactory' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'embeddedMongoServer' defined in class path resource 

[org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfiguration.class]: Unsatisfied dependency expressed through method 'embeddedMongoServer' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'embeddedMongoConfiguration' defined in class path resource 

[org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [de.flapdoodle.embed.mongo.config.MongodConfig]: Factory method 'embeddedMongoConfiguration' threw exception; nested exception is java.lang.ArrayIndexOutOfBoundsException: Index 2 out of bounds for length 2

使用Sping Boot 2.7.10如何使其与@SpringBootTest annotation一起工作?

monwx1rj

monwx1rj1#

它使用这些属性,从4.4降级embedded-mongo并提供完整的uri

spring.mongodb.embedded.version=3.6.5
spring.data.mongodb.uri=mongodb://localhost:27017/yourDB

相关问题