[英]Accessing CloudFoundry user-provided services using Spring Cloud connectors
I'm trying to use Spring Cloud to consume a generic REST service from a Cloud Foundry app. 我正在尝试使用Spring Cloud从Cloud Foundry应用程序中使用通用REST服务。
This service is created using Spring Boot, as follows: 此服务使用Spring Boot创建,如下所示:
package com.something;
@RestController
public class DemoServiceController {
@RequestMapping("/sayHi")
public String sayHi() {
return "Hello!";
}
}
This works fine - I can access http://www.example.com/srv/demo/sayHi
and get "Hello!" 这很好 - 我可以访问
http://www.example.com/srv/demo/sayHi
并获得“你好!” back. 背部。
Next, I created a user-provided service instance using the CF-CLI and bound it to my app. 接下来,我使用CF-CLI创建了一个用户提供的服务实例,并将其绑定到我的应用程序。 I can now see the bound service in
VCAP_SERVICES
. 我现在可以在
VCAP_SERVICES
看到绑定服务。
cf cups my-demo-service -p '{"url":"http://www.example.com/srv/demo/"}'
cf bs my-demo-app my-demo-service
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). 接下来,描述在这里 ,我加入这个bean到我的应用程序的Spring配置,与
connector-type
设置为我原来的控制器(我对它的引用以及)。
<cloud:service id="myDemoService"
service-name="my-demo-service"
connector-type="com.something.DemoServiceController"
/>
Now when I auto-wire "myDemoService"
into my app, 现在,当我将
"myDemoService"
自动"myDemoService"
到我的应用程序时,
@Autowired
private DemoController myDemoService;
I get an error: 我收到一个错误:
No services of the specified type could be found.
找不到指定类型的服务。
I've made sure to include all required dependencies, including spring-cloud-spring-service-connector
and spring-cloud-cloudfoundry-connector
. 我已经确保包含所有必需的依赖项,包括
spring-cloud-spring-service-connector
和spring-cloud-cloudfoundry-connector
。
What's going wrong here? 这里出了什么问题? Am I giving the wrong bean parameters?
我给出了错误的bean参数吗? Any help is much appreciated.
任何帮助深表感谢。
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). Spring Cloud Connectors不知道该如何处理这项服务,因为每个支持的服务必须是已知类型(MySQL,Postgres,Redis,MongoDB,RabbitMQ等)。 Setting the
connector-type
to your Controller class won't do what you want. 将
connector-type
设置为Controller类将无法执行所需操作。
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 .
以下是一个项目的示例: https : //github.com/cf-platform-eng/spring-boot-cities 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.