【发布时间】:2014-05-27 13:44:33
【问题描述】:
如何将 Cloud Foundry 服务连接到 Spring Boot Maven 项目?我认为将spring.data.mongodb.uri = uri 放入属性文件可以解决问题。是否有其他步骤可以连接到在 Cloud Foundry 中创建的服务?谢谢。顺便说一句,我通过在部署步骤中检查服务来使用 sts 添加服务。
@Bean
public MongoDbFactory mongoDbFactory() {
CloudEnvironment cloudEnvironment = new CloudEnvironment();
MongoServiceInfo serviceInfo = cloudEnvironment.getServiceInfo("servicename", MongoServiceInfo.class);
MongoServiceCreator serviceCreator = new MongoServiceCreator();
return serviceCreator.createService(serviceInfo);
}
所以我添加了这段代码,但它仍然挂在部署中。服务名是服务实例名吗?
【问题讨论】:
-
这应该可以工作(显然你需要正确的“uri”环境变量)。你实际上做了什么,发生了什么?
-
我被困在
Deploying application... Generating application archive... Pushing application to Cloud Foundry server... Processing payload... . Staging application... Waiting for application to start... .................. .................... .................... -
您正在使用 STS 进行部署?它是否可以从命令行工作(例如“cf push myapp -p target/*.jar”)?
-
是的。我在 sts 中部署。我想对我来说真正的问题是当我删除数据库时数据库的连接,部署成功。你有我可以遵循的示例程序吗? posgresql、mongodb 或 cleardb。谢谢
-
这里有一个不同平台的示例:github.com/spring-projects/spring-boot/issues/668。如果你只是拉出 URL 的东西,它应该以同样的方式工作。
标签: java spring-mvc cloud-foundry spring-boot