java - 找不到合适的 ServiceConnectorCreator 错误 - Spring cloud/CloudFoundry

标签 java spring ibm-cloud cloud-foundry spring-cloud

全部,

当我尝试推送到 IBM Bluemix/CloudFoundry 时,我有一个 spring boot 应用程序出现错误。

这是一个 spring boot 应用程序,使用 spring cloud 并尝试连接到关系数据库服务(sqldb,它是 DB2 的云版本)服务。

我可以在没有 spring cloud 的情况下进行连接,我在我的属性文件中明确指定了来自 vcap_services 的数据库凭据。但是,我试图避免使用 spring cloud 抽象,但出现了下面提到的错误。

我的期望是 spring boot/cloud 应该识别我绑定(bind)到应用程序的 test-sqldb 服务并即时创建数据源。相反,当我执行 cf push 时,我得到了下面给出的错误。

假设 spring boot/cloud 对会为我编排数据源是否公平,因为我在环境中有 db2 驱动程序 jar 和附加服务。?如果没有,有人可以指出我错过了什么吗?

Pom.xml

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependenc

    <dependency>
        <groupId>com.ibm.db2</groupId>
        <artifactId>db2jcc </artifactId>
        <version>10.5</version>
   </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-cloudfoundry-connector</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-spring-service-connector</artifactId>
    </dependency>
</dependencies>

我在 spring 上下文文件中有以下配置,如 this 中所述关联。 使用云配置文件与我的本地数据源配置分开。

spring 配置 - 这被导入到我的 spring 上下文中,并且在我使用云配置文件运行时生效

<beans profile="cloud">
    <cloud:data-source id="dataSourcePref" service-name="test-sqldb">
        <!-- <cloud:pool-data-sources>
            <value>TomcatJdbc</value>
            <value>TomcatDbcp</value>
            <value>BasicDbcp</value>
        </cloud:pool-data-sources>-->
    </cloud:data-source>
</beans>    

Spring Boot 应用类

@SpringBootApplication
@ImportResource("classpath:/META-INF/spring/my-jpa-beans.xml")
public class JpaTestApplication {

    public static void main(String[] args) {
       SpringApplication.run(JpaTestApplication.class, args);
    }
 }

错误

    2015-10-28T09:47:11.11-0700 [App/0]      OUT 2015-10-28 16:47:11.115 ERROR 29 --- [           main] o.s.boot.SpringApplication               : Application startup failed
2015-10-28T09:47:11.11-0700 [App/0]      OUT org.springframework.beans.factory.BeanCreationException: Error registering service factory; nested exception is org.springframework.cloud.CloudException: No suitable ServiceConnectorCreator found: service id=test-sqldb, service info type=org.springframework.cloud.service.BaseServiceInfo, connector type=interface javax.sql.DataSource
2015-10-28T09:47:11.11-0700 [App/0]      OUT    at org.springframework.cloud.config.xml.CloudServiceIntroducer.postProcessBeanFactory(AbstractCloudServiceFactoryParser.java:90)
2015-10-28T09:47:11.11-0700 [App/0]      OUT    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:265)
2015-10-28T09:47:11.11-0700 [App/0]      OUT    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:177)
2015-10-28T09:47:11.11-0700 [App/0]      OUT    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:607)
2015-10-28T09:47:11.11-0700 [App/0]      OUT    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:462)
2015-10-28T09:47:11.11-0700 [App/0]      OUT    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:117)
2015-10-28T09:47:11.11-0700 [App/0]      OUT    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:689)
2015-10-28T09:47:11.11-0700 [App/0]      OUT    at org.springframework.boot.SpringApplication.run(SpringApplication.java:321)
2015-10-28T09:47:11.11-0700 [App/0]      OUT    at org.springframework.boot.SpringApplication.run(SpringApplication.java:969)
2015-10-28T09:47:11.11-0700 [App/0]      OUT    at org.springframework.boot.SpringApplication.run(SpringApplication.java:958)
2015-10-28T09:47:11.11-0700 [App/0]      OUT    at com.example.JpaTestApplication.main(JpaTestApplication.java:14)
2015-10-28T09:47:11.11-0700 [App/0]      OUT    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2015-10-28T09:47:11.11-0700 [App/0]      OUT    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
2015-10-28T09:47:11.11-0700 [App/0]      OUT    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
2015-10-28T09:47:11.11-0700 [App/0]      OUT    at java.lang.reflect.Method.invoke(Method.java:497)
2015-10-28T09:47:11.11-0700 [App/0]      OUT    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:53)
2015-10-28T09:47:11.11-0700 [App/0]      OUT    at java.lang.Thread.run(Thread.java:745)
2015-10-28T09:47:11.11-0700 [App/0]      OUT Caused by: org.springframework.cloud.CloudException: No suitable ServiceConnectorCreator found: service id=test-sqldb, service info type=org.springframework.cloud.service.BaseServiceInfo, connector type=interface javax.sql.DataSource
2015-10-28T09:47:11.11-0700 [App/0]      OUT    at org.springframework.cloud.ServiceConnectorCreatorRegistry.getServiceCreator(Cloud.java:356)
2015-10-28T09:47:11.11-0700 [App/0]      OUT    at org.springframework.cloud.Cloud.getServiceConnector(Cloud.java:255)
2015-10-28T09:47:11.11-0700 [App/0]      OUT    at org.springframework.cloud.Cloud.getServiceConnector(Cloud.java:142)
2015-10-28T09:47:11.11-0700 [App/0]      OUT    at org.springframework.cloud.service.AbstractCloudServiceConnectorFactory.createService(AbstractCloudServiceConnectorFactory.java:103)
2015-10-28T09:47:11.11-0700 [App/0]      OUT    at org.springframework.cloud.service.AbstractCloudServiceConnectorFactory.createInstance(AbstractCloudServiceConnectorFactory.java:98)
2015-10-28T09:47:11.11-0700 [App/0]      OUT    at org.springframework.beans.factory.config.AbstractFactoryBean.afterPropertiesSet(AbstractFactoryBean.java:134)
2015-10-28T09:47:11.11-0700 [App/0]      OUT    at org.springframework.cloud.service.AbstractCloudServiceConnectorFactory.afterPropertiesSet(AbstractCloudServiceConnectorFactory.java:93)
2015-10-28T09:47:11.11-0700 [App/0]      OUT    at org.springframework.cloud.config.xml.CloudServiceIntroducer.postProcessBeanFactory(AbstractCloudServiceFactoryParser.java:82)
2015-10-28T09:47:11.11-0700 [App/0]      OUT    ... 16 common frames omitted
2015-10-28T09:47:11.26-0700 [DEA/17]     ERR Instance (index 0) failed to start accepting connections

最佳答案

看来我明白发生了什么。

this 中的答案线程提到了有关服务连接器的信息,这给了我一个提示。

SqlDb 需要 DB2DataSourceCreator,它在我使用的 spring-cloud-connectors 版本 1.1.1-release 中不可用。它支持其他如 MySQL、Postgres、Redis、MongoDB、RabbitMQ 等。

升级到 1.2.0-release,我可以通过这个错误点。 感谢你们两个试图提供帮助的人。

关于java - 找不到合适的 ServiceConnectorCreator 错误 - Spring cloud/CloudFoundry,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33399053/

相关文章:

java - 如何在 Scala 中以字符串格式重复参数

java - 设置循环播放音频文件后逐个播放

java - manipule jBPM 5.4 模拟定时器事件的时间

ibm-cloud - 如何查找 IBM API 的用户 ID 和密码?

javascript - 如何在 Jade 模板中使用 Javascript 变量?

java - HTTP POST 方法返回状态代码 404

java - Spring Controller单元测试最佳实践

Spring MVC/安全 - "Store is closed"安全过滤器

spring - 在 Spring 测试中禁用 @EnableScheduling

db2 - bluemix DataCache 同步到 DB2