java - 部署和连接云类型转换服务(MongoDB、Java、Spring Boot)

标签 java spring-mvc cloud-foundry spring-boot

如何将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);
    }

所以我添加了此代码,但它仍然卡在部署中。服务名称是服务实例名称吗?

最佳答案

为了连接 Cloud Foundry 服务,您必须使用 @Configuration 注解扩展 Spring Boot App 中的 AbstractCloudConfig 类。我建议您阅读https://docs.cloudfoundry.org/buildpacks/java/configuring-service-connections/spring-service-bindings.html#javaconfig

关于java - 部署和连接云类型转换服务(MongoDB、Java、Spring Boot),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23045856/

相关文章:

java - 添加Spring库时出现"Given parent is not an ancestor of this virtual file"错误

java - 使用 Netbeans 自动最大化窗口

java - 在哪里使用 @SuppressWarnings ("requestfactory")

java - 如何覆盖 glassfish 中的 j_security_check?

java - 如何在 spring mvc 中使用 HandlerInterceptorAdapter 手动处理 session 超时

java - 具有自定义状态代码的 Spring Boot Controller ?

cloud-foundry - 将应用程序推送到 Cloud Foundry 时出错 : FAILED Error processing app file: The directory is not empty

node.js - Cloud Foundry 和 Socket.IO 跨域策略问题

java - JPA 查询子句 Where

linux - 应用程序的性能测试 - Cloud foundry