title: db2 as a service in Cloud foundry
body: <p>Im trying to connect to db2 service defined in my Cloudfoundry and it is bound to my application.</p>
  
  <pre><code>@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); 
      } 
  
  }
  </code></pre>
  
  <p>I have added below 2 files in resource Path /META-INF/services</p>
  
  <pre><code>org.springframework.cloud.cloudfoundry.CloudFoundryServiceInfoCreator(File)
  org.springframework.cloud.cloudfoundry.DB2ServiceInfoCreator
  
  org.springframework.cloud.service.ServiceConnectorCreator (File)
  org.springframework.cloud.service.relational.DB2DataSourceCreator
  </code></pre>
  
  <p>Getting below error</p>
  
  <blockquote>
    <p>2016-07-14T03:19:44.44-0400 [APP/0] OUT 2016-07-14 07:19:44.444 WARN
    14 --- [ main] o.c.r.o.s.cloud.AbstractCloudConnector : No suitable
    service info creator found for service db2-srvc Did you forget to add
    a ServiceInfoCreator?</p>
  </blockquote>
  
  <p>2016-07-14T03:19:44.51-0400 [APP/0] OUT 2016-07-14 07:19:44.510 INFO 14 --- [ main] nfigurationApplicationContextInitializer : Adding cloud service auto-reconfiguration to ApplicationContext
  2016-07-14T03:19:45.15-0400 [APP/0] OUT 2016-07-14 07:19:45.154 INFO 14 --- [ main] c.e.config.ApplicationIntializer : Cloud profile active</p>
  
  <p>.....</p>
  
  <p>.....</p>
  
  <p>org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.sql.DataSource org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.dataSource; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'db2service' defined in class path resource [com/eclipselite/config/Db2CloudConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'db2service' threw exception; nested exception is java.lang.ClassCastException: org.springframework.cloud.service.BaseServiceInfo cannot be cast to 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 at org.springframework.beans.factory.support</p>
  
  <p>......</p>
  
  <p>......</p>
  
  <p>:52.50-0400 [APP/0] OUT Caused by: java.lang.ClassCastException: org.springframework.cloud.service.BaseServiceInfo cannot be cast to org.springframework.cloud.service.common.DB2ServiceInfo
  2016-07-14T03:19:52.50-0400 [APP/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</p>