在 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")
你能帮我解决这个问题吗?