简体   繁体   English

使用Spring Cloud连接器访问CloudFoundry用户提供的服务

[英]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-connectorspring-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.

相关问题 在春季启动中无法从vcap_services中提供的用户中检索凭证 - Unable to retrieve credentials from user-provided in vcap_services in spring boot 使用用户提供的用户名/密码进行Java JDBC登录 - Java JDBC Login with user-provided username/password Java BigDecimal - 向下舍入到用户提供的多个 - Java BigDecimal - rounding down to the user-provided multiple 如何在Android应用中运行用户提供的任意代码? - How to run user-provided, arbitrary code in an android app? 用Java确定用户提供的数组的最大值和均值 - Determining Maximum and Mean of an User-Provided Array in Java 春云; CloudFoundry; spring.jpa属性 - Spring Cloud; CloudFoundry; spring.jpa properties 没有找到合适的ServiceConnectorCreator错误 - Spring cloud / CloudFoundry - No suitable ServiceConnectorCreator found error - Spring cloud/CloudFoundry Spring应用程序无法在Cloudfoundry中读取的云属性 - Cloud properties not read by Spring application in Cloudfoundry 无法在 Cloud Foundry 中使用 Spring Cloud 连接器设置 connectionProperties - Cannot set connectionProperties with Spring Cloud Connectors in Cloud Foundry spark下载页面上预建和用户提供的hadoop有什么区别? - What are the differences between pre-built and user-provided hadoop on spark download page?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM