我跟着这个guide用mongoDB设置了一个gradle Springboot服务,然后跟着deployment instructions用于heroku。我还添加了mongoLab addOn。它在localhost上完美运行,但是当在heroku上访问数据库部分时,响应无限期地停止。当我删除mongoDB行并重新部署时,响应完美无缺。如何在mongoDB工作的情况下将此应用程序部署到heroku?
编辑:这是来自heroku日志的错误
org.mongodb.driver.cluster : No server chosen by WritableServerSelector from cluster description ClusterDescription{type=UNKNOWN, connectionMode=SINGLE, serverDescriptions=[ServerDescription{address=localhost:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused (Connection refused)}}]}. Waiting for 30000 ms before timing out
答案 0 :(得分:0)
我必须添加一个mongoLab配置。
@Configuration
public class MongoLabConfiguration {
public @Bean MongoDbFactory mongoDbFactory() throws MongoException, UnknownHostException {
return new SimpleMongoDbFactory(new MongoClientURI(System.getenv("MONGODB_URI")));
}
public @Bean
MongoTemplate mongoTemplate() throws Exception {
return new MongoTemplate(mongoDbFactory());
}
}