尝试使用本地 spring 云连接器/local_configuration_connector 时找不到合适的云连接器 [英] No suitable cloud connector found while trying to use local spring cloud connector/local_configuration_connector

查看:25
本文介绍了尝试使用本地 spring 云连接器/local_configuration_connector 时找不到合适的云连接器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用本地云 spring 连接器在本地环境中测试我的应用程序,然后才能将其部署到基于 CF 的云环境.来自 Spring 链接

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

我按照流程在项目资源目录中创建了名为 spring-cloud-bootstrap.properties 的属性文件.它有以下内容

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

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

我确实在上面给出的路径中有文件 spring-cloud.properties.

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

从 spring 配置 bean 我有以下

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);

}

现在这个 DataSource bean 被注入到其他各个地方.有了属性文件,我希望将创建用于本地配置的云连接器 bean,我应该能够使用它为连接池的数据源添加更多配置.

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.

注意:我尝试将属性文件放在不同的位置,例如(直接在应用程序根目录下、web-inf/lib 中、资源中等)

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

这里有什么帮助吗?

推荐答案

在最近的一个项目中,我们遇到了同样的问题.在云中一切正常,但在本地抛出错误找不到合适的云连接器".为了排除依赖问题,在我们的例子中(Spring Boot 微服务部署在 CloudFoundry 环境中)以下两个依赖(依赖管理管理的版本)就足够了.

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>

应该使用的 CloudFoundryConnector 会检查是否设置了环境变量 VCAP_APPLICATION,然后才将自己标记为合适,否则什么都不做.在本地环境中复制 VCAP_SERVICES 和 VCAP_APPLICATION 变量通常被认为是一种反模式,但在我们的用例中,这正是使一切在本地尽可能接近云环境的解决方案.

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.

这篇关于尝试使用本地 spring 云连接器/local_configuration_connector 时找不到合适的云连接器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆