繁体   English   中英

在不实例化mongo的情况下构建spring boot项目

[英]build spring boot project without instantiating mongo

我有一个具有mongo依赖项的spring boot项目。 使用mvn clean package进行spring.data.mongodb.host=localhost可以使用spring.data.mongodb.host=localhost但是当我使用spring.data.mongodb.host=<remote-ip-address>它将失败。 由于我无法访问本地计算机上的ip地址,因此可以在不使用Spring尝试连接到mongo的情况下构建jar。

现在,它给出了以下错误-

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoTemplate' defined in class path resource [org/springframework/boot/autoconfigure/data/mongo/MongoDataAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.mongodb.core.MongoTemplate]: Factory method 'mongoTemplate' threw exception; nested exception is org.springframework.dao.DataAccessResourceFailureException: Timed out after 30000 ms while waiting for a server that matches WritableServerSelector. Client view of cluster state is {type=UNKNOWN, servers=[{address=10.37.130.100:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketReadException: Exception receiving message}, caused by {java.net.SocketException: Operation timed out}}]; nested exception is com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches WritableServerSelector. Client view of cluster state is {type=UNKNOWN, servers=[{address=10.37.130.100:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketReadException: Exception receiving message}, caused by {java.net.SocketException: Operation timed out}}]

默认情况下,在Spring Boot应用程序的构建中有一个测试,它检查上下文,并且它已打开。 只需将其关闭(-DskipTests属性)。

或使用-Dspring.data.mongodb.host = localhost进行集成测试。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM