No suitable cloud connector found while trying to use local spring cloud connector/local_configuration_connector

僤鯓⒐⒋嵵緔 提交于 2019-12-04 16:38:17

In a recent project we had the same issue. In the cloud everything worked, but locally the error "No suitable cloud connector found" was thrown. To rule out dependency issues, in our case (Spring Boot microservice to be deployed in a CloudFoundry environment) the following two dependencys (version managed by the dependency management) were sufficient.

<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-spring-service-connector</artifactId>
</dependency>
<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-cloudfoundry-connector</artifactId>
</dependency>

The CloudFoundryConnector that should be used checks if there is an environment variable VCAP_APPLICATION set, and only then marks itself as suitable, else it will do nothing. It is commonly said to be an antipattern to replicate the VCAP_SERVICES and VCAP_APPLICATION variables in a local environment, but in our usecase this was exactly the solution to make everything work locally as close as possible to the cloud environment.

This answer is probably too late for the original question, but as a starting point for other lost souls, who happen to have the same problem, it will hopefully save others the debugging time we spent.

Are you using the maven shade plugin to package your application? If so, make sure to have the <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/> in place.

As far as I analyzed when this is missing the Cloud-Foundry connector overrides/overlays the ServiceLoaders from the Local-Connector.

All of this of course only if you're trying to run your locally built package. Directly from the IDE (IntelliJ in my case) it always worked.

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