[英]Db2Service issue-spring Cloud foundry
在Cloud Foundry中连接db2服务时遇到问题。 我已将服务创建为cf cups db2service -p“ jdbcUrl,user,password” 。在云上部署应用程序时,我遇到了一个类 强制转换 异常 ,也没有找到合适的连接器异常。以下是我的配置类。
@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);
}
}
我还在gradle文件中添加了以下依赖项。
compile("org.springframework.cloud:spring-cloud-spring-service-connector:1.2.0.RELEASE")
compile("org.springframework.cloud:spring-cloud-cloudfoundry-connector:1.2.0.RELEASE")
compile("org.springframework.cloud:spring-cloud-core:1.2.0.RELEASE")
您能帮我解决这个问题吗?
基于java.lang.ClassCastException: org.springframework.cloud.service.BaseServiceInfo cannot be cast to org.springframework.cloud.service.common.DB2ServiceInfo
异常,在我看来,您没有得到您认为的连接器依赖项你得到。
要确认这一点,请运行gradle :dependencies
任务,并查看您实际获得的版本。 该任务输出的相关部分应如下所示:
+--- org.springframework.cloud:spring-cloud-spring-service-connector: -> 1.2.0.RELEASE
| +--- org.springframework.cloud:spring-cloud-core:1.2.0.RELEASE
| \--- org.springframework:spring-context:3.1.4.RELEASE -> 4.1.7.RELEASE (*)
+--- org.springframework.cloud:spring-cloud-cloudfoundry-connector: -> 1.2.0.RELEASE
| \--- org.springframework.cloud:spring-cloud-core:1.2.0.RELEASE
如果我的预感是正确的,您可能会在输出中看到类似org.springframework.cloud:spring-cloud-spring-service-connector:1.2.0.RELEASE -> 1.1.1.RELEASE (*)
,表明该gradle选择使用的是其他过渡依赖项所要求的旧版本。 我已经在Spring Boot应用程序中看到了这种情况,因为Boot引入了旧版本的Connector。
如果确实看到该版本已降级,则应查看将Spring propdeps插件拉入以获得gradle以便直接获得依赖关系。
如果这不是问题,那么您将需要共享一个示例项目来演示此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.