我只是添加MongoDB配置到现有的Spring 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
使用Spring Boot 2.7.10如何使它与@SpringBootTest注释一起工作?
使用这些属性,将embedded-mongo从4.4降级并提供完整的uri
spring.mongodb.embedded.version=3.6.5
spring.data.mongodb.uri=mongodb://localhost:27017/yourDB