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

Manoj K Sardana picture Manoj K Sardana · Jan 3, 2017 · Viewed 11.2k times · Source

I am trying to use the local cloud spring connector to test my application in local environment before it can be deployed to CF based cloud environment. From the Spring link

http://cloud.spring.io/spring-cloud-connectors/spring-cloud-connectors.html#_local_configuration_connector

I followed the process and created properties file with the name spring-cloud-bootstrap.properties in project resource directory. It has the following content

spring.cloud.propertiesFile: C:\Users\IBM_ADMIN\git\ServiceXchange5\ServiceXchange\spring-cloud.properties

I do have the file spring-cloud.properties in the path given above.

From the spring configuaration bean I have the following

@EnableWebMvc
@Configuration
@EnableAspectJAutoProxy
public class CloudServiceConfig extends AbstractCloudConfig {

@Bean
public DataSource getDataSource() throws AppException  {

org.springframework.cloud.service.PooledServiceConnectorConfig.PoolConfig poolConfig = new PoolConfig(50, 100, 3000);
org.springframework.cloud.service.relational.DataSourceConfig dbConfig = new DataSourceConfig(poolConfig, null);
return connectionFactory().dataSource(SX_DB_USED, dbConfig);

}

Now this DataSource bean is injected in various other places. With the property files in places, I expect that cloud connector bean for local configuration will be created and I should be able to use the same to add more configuration for DataSource for connection pooling.

However when I access the application it seems local Configuration connector itself it not activated.

Initialization of bean failed; nested exception is org.springframework.cloud.CloudException: No suitable cloud connector found
[ERROR   ] SRVE0271E: Uncaught init() exception created by servlet [appServlet] in application [ServiceXchange]:  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cloudServiceConfig' defined in file [C:\Users\IBM_ADMIN\git\ServiceXchange5\ServiceXchange\target\classes\com\hcl\service\config\CloudServiceConfig.class]: Initialization of bean failed; nested exception is org.springframework.cloud.CloudException: No suitable cloud connector found
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:444)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:326)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
at com.ibm.ws.webcontainer.webapp.WebApp.notifyServletContextCreated(WebApp.java:2388)
at [internal classes]
Caused by: org.springframework.cloud.CloudException: No suitable cloud connector found
at org.springframework.cloud.CloudFactory.getCloud(CloudFactory.java:55)
at org.springframework.cloud.config.java.AbstractCloudConfig.setBeanFactory(AbstractCloudConfig.java:85)
at com.hcl.service.config.CloudServiceConfig$$EnhancerBySpringCGLIB$$9529c032.CGLIB$setBeanFactory$54(<generated>)
at com.hcl.service.config.CloudServiceConfig$$EnhancerBySpringCGLIB$$9529c032$$FastClassBySpringCGLIB$$6c6301dd.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanFactoryAwareMethodInterceptor.intercept(ConfigurationClassEnhancer.java:277)
at com.hcl.service.config.CloudServiceConfig$$EnhancerBySpringCGLIB$$9529c032.setBeanFactory(<generated>)
at org.springframework.context.annotation.ConfigurationClassPostProcessor$EnhancedConfigurationBeanPostProcessor.postProcessPropertyValues(ConfigurationClassPostProcessor.java:480)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
... 13 more

I am not sure why the local cloud connector is not activated. As per the link it should after detecting the properties files in place.

NOTE : I have tried putting the property file in different location like (directly under application root, in web-inf/lib, in resources etc)

Any help here ?

Answer

Thomas W picture Thomas W · Mar 15, 2018

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.