在没有实例化mongo的情况下构建spring启动项目

时间:2017-09-01 16:36:01

标签: java spring mongodb spring-boot

我有一个具有mongo依赖性的spring boot项目。使用mvn clean package进行构建可以使用spring.data.mongodb.host=localhost,但是当我使用spring.data.mongodb.host=<remote-ip-address>时,它会失败。由于我无法访问本地计算机上的IP地址,因此我可以在没有弹簧试图连接到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}}]

1 个答案:

答案 0 :(得分:1)

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

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

相关问题