簡體   English   中英

嘗試使用本地 spring 雲連接器/local_configuration_connector 時找不到合適的雲連接器

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

我正在嘗試使用本地雲 spring 連接器在本地環境中測試我的應用程序,然后才能將其部署到基於 CF 的雲環境。 來自 Spring 鏈接

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

我按照這個過程在項目資源目錄中創建了名為 spring-cloud-bootstrap.properties 的屬性文件。 它有以下內容

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

我確實在上面給出的路徑中有文件 spring-cloud.properties。

從 spring 配置 bean 我有以下內容

@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,我應該能夠使用它為連接池的數據源添加更多配置。

但是,當我訪問該應用程序時,它似乎沒有激活本地配置連接器本身。

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

我不確定為什么未激活本地雲連接器。 根據鏈接,它應該在檢測到適當的屬性文件后。

注意:我嘗試將屬性文件放在不同的位置,例如(直接在應用程序根目錄下、web-inf/lib 中、資源中等)

有什么幫助嗎?

在最近的一個項目中,我們遇到了同樣的問題。 在雲中一切正常,但在本地拋出錯誤“找不到合適的雲連接器”。 為了排除依賴問題,在我們的例子中(Spring Boot 微服務要部署在 CloudFoundry 環境中)以下兩個依賴(依賴管理管理的版本)就足夠了。

<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 變量是一種反模式,但在我們的用例中,這正是使一切在本地盡可能接近雲環境的解決方案。

對於最初的問題,這個答案可能為時已晚,但作為其他碰巧遇到相同問題的迷失靈魂的起點,它有望為其他人節省我們花費的調試時間。

如果您在本地運行,那么您可能無法獲得 Cloud 實例,從而導致這種情況。 需要確保它是用於本地還是在雲上,具體取決於使用情況。 就我而言,這是調用它的位置的問題。 因此,當部署在雲上時,我添加了一個額外的方法來實例化 cloudfoundry (CloudFactory().getCloud())。

您是否使用 maven shade 插件來打包您的應用程序? 如果是這樣,請確保有<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>到位。

據我分析,何時缺少 Cloud-Foundry 連接器覆蓋/覆蓋來自本地連接器的 ServiceLoaders。

當然,只有當您嘗試運行本地構建的程序包時,才可以執行所有這些操作。 直接從 IDE(在我的例子中是 IntelliJ)它總是有效的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM