【问题标题】:Accessing CloudFoundry user-provided services using Spring Cloud connectors使用 Spring Cloud 连接器访问 CloudFoundry 用户提供的服务
【发布时间】:2015-04-17 19:04:43
【问题描述】:

我正在尝试使用 Spring Cloud 从 Cloud Foundry 应用程序中使用通用 REST 服务。

这个服务是使用Spring Boot创建的,如下:

package com.something;

@RestController
public class DemoServiceController {
    @RequestMapping("/sayHi")
    public String sayHi() {
        return "Hello!";
    }
}

这很好用 - 我可以访问 http://www.example.com/srv/demo/sayHi 并得到“你好!”背部。

接下来,我使用 CF-CLI 创建了一个用户提供的服务实例并将其绑定到我的应用程序。我现在可以在VCAP_SERVICES 中看到绑定的服务。

cf cups my-demo-service -p '{"url":"http://www.example.com/srv/demo/"}'
cf bs my-demo-app my-demo-service

接下来,如 here 所述,我将此 bean 添加到我的应用程序的 Spring 配置中,并将 connector-type 设置为我的原始控制器(我也有它的引用)。

<cloud:service id="myDemoService"
               service-name="my-demo-service"
               connector-type="com.something.DemoServiceController"
               />

现在,当我将 "myDemoService" 自动连接到我的应用时,

@Autowired
private DemoController myDemoService;

我收到一个错误:

找不到指定类型的服务。

我已确保包含所有必需的依赖项,包括 spring-cloud-spring-service-connectorspring-cloud-cloudfoundry-connector

这里出了什么问题?我是否提供了错误的 bean 参数?非常感谢任何帮助。

【问题讨论】:

  • 您可以尝试常规服务而不是用户提供的服务吗?只是想尝试隔离这两种服务是否都有问题。
  • @JeffSloyer 它仍然需要是自定义服务。内置的都在 spring-cloud-connectors 中有特定的注解。
  • 没关系,我只是想看看它是否与用户提供的服务或常规服务有关。可以试试常规服务,看看行为是否相同?

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


【解决方案1】:

Spring Cloud 连接器不知道如何处理此服务,因为每个支持的服务必须是已知类型(MySQL、Postgres、Redis、MongoDB、RabbitMQ 等)。将 connector-type 设置为您的 Controller 类不会满足您的要求。

您需要做的是创建一个自定义连接器扩展。以下是执行此操作的项目示例:https://github.com/cf-platform-eng/spring-boot-cities

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-17
    • 2018-05-31
    • 2015-09-18
    • 2018-05-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多