使用Spring Cloud连接器访问CloudFoundry用户提供的服务 [英] Accessing CloudFoundry user-provided services using Spring Cloud connectors
问题描述
我正在尝试使用Spring Cloud从Cloud Foundry应用程序中使用通用REST服务。
I'm trying to use Spring Cloud to consume a generic REST service from a Cloud Foundry app.
此服务是使用Spring Boot创建的,如下所示:
This service is created using Spring Boot, as follows:
package com.something;
@RestController
public class DemoServiceController {
@RequestMapping("/sayHi")
public String sayHi() {
return "Hello!";
}
}
这很好用 - 我可以访问 http://www.example.com/srv/demo/sayHi
并获取Hello!背部。
This works fine - I can access http://www.example.com/srv/demo/sayHi
and get "Hello!" back.
接下来,我使用CF-CLI创建了一个用户提供的服务实例,并将其绑定到我的应用程序。我现在可以在 VCAP_SERVICES
中看到绑定服务。
Next, I created a user-provided service instance using the CF-CLI and bound it to my app. I can now see the bound service in VCAP_SERVICES
.
cf cups my-demo-service -p '{"url":"http://www.example.com/srv/demo/"}'
cf bs my-demo-app my-demo-service
接下来,如描述这里,我将这个bean添加到我的应用程序的Spring配置中, connector-type
设置为原始控制器(我也引用了它)。
Next, as described here, I added this bean to my app's Spring config, with the connector-type
set to my original controller (I have a reference to it as well).
<cloud:service id="myDemoService"
service-name="my-demo-service"
connector-type="com.something.DemoServiceController"
/>
现在当我自动连接myDemoService
进入我的应用程序,
Now when I auto-wire "myDemoService"
into my app,
@Autowired
private DemoController myDemoService;
我收到错误消息:
找不到指定类型的服务。
No services of the specified type could be found.
我确保包含所有必需的依赖项,包括 spring-cloud-spring-service-connector
和 spring-cloud-cloudfoundry-connector
。
I've made sure to include all required dependencies, including spring-cloud-spring-service-connector
and spring-cloud-cloudfoundry-connector
.
这里出了什么问题?我给出了错误的bean参数吗?非常感谢任何帮助。
What's going wrong here? Am I giving the wrong bean parameters? Any help is much appreciated.
推荐答案
Spring Cloud Connectors不知道如何处理此服务,因为每个支持的服务必须属于已知类型(MySQL,Postgres,Redis,MongoDB,RabbitMQ等)。将连接器类型
设置为Controller类将无法执行所需操作。
Spring Cloud Connectors won't know what to do with this service, as each supported service must be of a known type (MySQL, Postgres, Redis, MongoDB, RabbitMQ, etc). Setting the connector-type
to your Controller class won't do what you want.
您需要做的是创建自定义连接器扩展。以下是一个项目的示例: https://github.com/cf -platform-eng / spring-boot-cities 。
What you will need to do is to create a custom Connectors extension. Here's an example of a project that does that: https://github.com/cf-platform-eng/spring-boot-cities.
这篇关于使用Spring Cloud连接器访问CloudFoundry用户提供的服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!