[英]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.