Accessing CloudFoundry user-provided services using Spring Cloud connectors

不羁的心 提交于 2019-12-06 06:28:59

问题


I'm trying to use Spring Cloud to consume a generic REST service from a Cloud Foundry app.

This service is created using Spring Boot, as follows:

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!" back.

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

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"
               />

Now when I auto-wire "myDemoService" into my app,

@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.

What's going wrong here? Am I giving the wrong bean parameters? Any help is much appreciated.


回答1:


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.

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://stackoverflow.com/questions/28555505/accessing-cloudfoundry-user-provided-services-using-spring-cloud-connectors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!