2017-09-01 53 views
0

我有一個mongo依賴的spring引導項目。建築使用mvn clean package工程使用spring.data.mongodb.host=localhost,但是當我使用spring.data.mongodb.host=<remote-ip-address>它失敗。由於我沒有訪問我的本地計算機上的IP地址,我可以在沒有彈簧的情況下構建jar來嘗試連接到mongo。沒有實例化mongo構建spring引導項目

現在它給下面的錯誤 -

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}}]

回答

0

在春季啓動應用程序的構建默認有一個測試,檢查範圍內,它的開啓。只需關閉它(-DskipTests屬性)。

或者用-Dspring.data.mongodb.host = localhost進行集成測試。