我试图连接到在我的Cloudfoundry中定义的db2服务,并且它绑定到我的应用程序。db2作为Cloud Foundry中的服务
@Configuration
@ServiceScan
@Profile("cloud")
public class Db2CloudConfig extends AbstractCloudConfig {
@Bean
public DataSource db2servicenew() {
CloudFactory cloudFactory = new CloudFactory();
Cloud cloud = cloudFactory.getCloud();
DB2ServiceInfo db2ServiceInfo= (DB2ServiceInfo) cloud.getServiceInfo("db2servicenew");
return cloud.getServiceConnector(db2ServiceInfo.getId(), DataSource.class, null);
}
@Bean(name = "db2JdbcTemplate")
public JdbcTemplate jdbcTemplate(DataSource db2servicenew) {
return new JdbcTemplate(db2servicenew);
}
}
低于资源路径2页的文件,我已经添加/ META-INF /服务
org.springframework.cloud.cloudfoundry.CloudFoundryServiceInfoCreator(File)
org.springframework.cloud.cloudfoundry.DB2ServiceInfoCreator
org.springframework.cloud.service.ServiceConnectorCreator (File)
org.springframework.cloud.service.relational.DB2DataSourceCreator
获得以下错误
2016-07-14T03:19:44.44-0400 [ APP/0] OUT 2016-07-14 07:19:44.444 WARN 14 --- [main] ocroscloud.AbstractCloudConnector:不适合 服务信息创建者发现服务db2-srvc您忘记添加 a Serv iceInfoCreator?
2016-07-14T03:19:44.51-0400 [APP/0] OUT 2016年7月14日07:19:44.510 INFO 14 --- [主要] nfigurationApplicationContextInitializer:添加云服务自动重新配置到ApplicationContext 2016-07-14T03:19:45.15-0400 [APP/0] OUT 2016-07-14 07:19:45.154 INFO 14 --- [main] ceconfig.ApplicationIntializer:Cloud profile active
。 ....
.....
org.springframework.beans.factory.BeanCreationException:错误创建豆名称为'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration':注入自动装配依赖失败;嵌套异常是org.springframework.beans.factory.BeanCreationException:无法自动装入字段:private javax.sql.DataSource org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.dataSource;嵌套异常是org.springframework.beans.factory.BeanCreationException:在类路径资源[com/eclipselite/config/Db2CloudConfig.class]中定义名称为'db2service'的bean时出错:通过工厂方法的Bean实例化失败;嵌套异常是org.springframework.beans.BeanInstantiationException:无法实例化[javax.sql.DataSource]:工厂方法'db2service'抛出异常;嵌套异常是java.lang.ClassCastException:org.springframework.cloud.service.BaseServiceInfo不能转换为org.springframework.cloud.service.common.DB2ServiceInfo 2016-07-14T03:19:52.50-0400 [APP/0] OUT at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)〜[spring-beans-4.2.6.RELEASE.jar!/:4.2.6.RELEASE] 2016-07-14T03 :19:52.50-0400 [APP/0] OUT at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)〜[spring-beans-4.2.6.RELEASE.jar!/:4.2 .6.RELEASE] 2016-07-14T03:19:52.50-0400 [APP/0] OUT at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)〜[spring-beans- 4.2.6.RELEASE.jar!/:4.2.6.RELEASE] 2016-07-14T03:19:52.50-0400 [APP/0] OUT在org.springframework.beans.factory.support
......
......
:52.50-0400 [APP/0] OUT引起:java.lang.ClassCastException:org.springframework.cloud.service.BaseServiceInfo无法转换为org.springframework.cloud.service.common.DB2ServiceInfo 2016-07- 14T03:19:52.50-0400 [com/0] OUT at com.eclipselite.config.Db2CloudConfig.db2service(Db2CloudConfig.java:43)〜[app /:na] 2016-07-14T03:19:52.50-0400 [ APP/0] OUT at com.eclipselite.config.Db2CloudConfig $ EnhancerBySpringCGLIB $$ 95090e1d。CGLIB $ db2service $ 1()〜[app /:na] 2016-07-14T03:19:52.50-0400 [APP/0] OUT at com.eclipselite.config.Db2CloudConfig $ EnhancerBySpringCGLIB $$ 95090e1d $ FastClassBySpringCGLIB $$ 5de8a91d。 invoke()〜[app /:na] 2016-07-14T03:19:52.50-0400 [APP/0] OUT at org.springfr
您是否在引用Bluemix上的“DB2 on Cloud”服务或其他方案?您的CF环境托管在哪里?请添加有关常规设置的详细信息 –
我们的组织中有一个私有云,与Pivotal Cloud代工厂相关联。我们在同一个GRN中有db2数据库。我能够直接访问相同的db2。但是当我定义相同的用户定义服务获取上述错误。 –