db2 as a service in Cloud foundry - db2

Im trying to connect to db2 service defined in my Cloudfoundry and it is bound to my application.
#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);
}
}
I have added below 2 files in resource Path /META-INF/services
org.springframework.cloud.cloudfoundry.CloudFoundryServiceInfoCreator(File)
org.springframework.cloud.cloudfoundry.DB2ServiceInfoCreator
org.springframework.cloud.service.ServiceConnectorCreator (File)
org.springframework.cloud.service.relational.DB2DataSourceCreator
Getting below error
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?
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
.....
.....
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
......
......
: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

I think If you are creating using serviceInfo it looks for certain tags/properties in cups. You can create a data source using connectionFactory.datasource("cups service name") or define the cups correctly as mentioned in the following document http://cloud.spring.io/spring-cloud-connectors/spring-cloud-cloud-foundry-connector.html#_db2

Related

SpringData JPA Transaction management

please help me about Spring JPA Transaction Management
I have two methods: usersService.addUser and authoritiesService.addNew
#Service
#Transactional(propagation = PROPAGATION.SUPPORTS, readOnly=true)
public class UsersService {
#Autowired
UsersRepository usersRepository;
#Autowired
AuthotitiesRepository authoritiesReposotory;
#Transaction
public addUser(...){
usersRespository.addUser...
authoritiesRepository.addNew...
}
...
public interface UsersRepository extends JpaRepository<Users, String> {
#Transactional
#Modifying
#Query(value = "insert into users..."
}
public interface AuthoritiesRepository extends JpaRepository<Users, String> {
#Transactional
#Modifying
#Query(value = "insert into abc ...."
}
The problem is when authoritiesRepository.addNew throws Exception(by some SQL syntax) I want to automatically rollback user info.
How can I configure in repository, service ?
Here is the exception trace:
2019-05-22 08:33:16.185 WARN 2276 --- [nio-8080-exec-4] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 42102, SQLState: 42S02
2019-05-22 08:33:16.185 ERROR 2276 --- [nio-8080-exec-4] o.h.engine.jdbc.spi.SqlExceptionHelper : Table "AUTHORITIESS" not found; SQL statement:
insert into authoritiess(username, authority) values(?, ?) [42102-199]
2019-05-22 08:33:16.220 ERROR 2276 --- [nio-8080-exec-4] o.s.t.i.TransactionInterceptor : Application exception overridden by commit exception
com.springboot.example.exception.DbCRUDException: Error on add user
at com.springboot.example.security.service.UsersService.addUser(UsersService.java:141) ~[classes/:na]
at com.springboot.example.security.service.UsersService$$FastClassBySpringCGLIB$$3d37fb4e.invoke() ~[classes/:na]
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) [spring-core-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:749) [spring-aop-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) [spring-aop-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139) ~[spring-tx-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.17.jar:9.0.17]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_162]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_162]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.17.jar:9.0.17]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_162]
Caused by: com.springboot.example.exception.DbCRUDException: Error on add authority
at com.springboot.example.security.service.AuthoritiesService.addNew(AuthoritiesService.java:58) ~[classes/:na]
at com.springboot.example.security.service.UsersService.addUser(UsersService.java:139) ~[classes/:na]
... 114 common frames omitted
Caused by: org.springframework.dao.InvalidDataAccessResourceUsageException: could not prepare statement; SQL [insert into authoritiess(username, authority) values(?, ?)]; nested exception is org.hibernate.exception.SQLGrammarException: could not prepare statement
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:279) ~[spring-orm-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:253) ~[spring-orm-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.data.jpa.repository.query.JpaQueryExecution$ModifyingExecution.doExecute(JpaQueryExecution.java:256) ~[spring-data-jpa-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:91) ~[spring-data-jpa-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:136) ~[spring-data-jpa-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:125) ~[spring-data-jpa-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:605) ~[spring-data-commons-2.1.6.RELEASE.jar:2.1.6.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$invoke$3(RepositoryFactorySupport.java:595) ~[sprin
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98) [spring-tx-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) [spring-aop-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139) ~[spring-tx-5.1.6.RELEASE.jar:5.1.6.RELEASE]
... 134 common frames omitted
Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "AUTHORITIESS" not found; SQL statement:
insert into authoritiess(username, authority) values(?, ?) [42102-199]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:451) ~[h2-1.4.199.jar:1.4.199]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:427) ~[h2-1.4.199.jar:1.4.199]
at org.h2.message.DbException.get(DbException.java:205) ~[h2-1.4.199.jar:1.4.199]
2019-05-22 08:33:16.226 ERROR 2276 --- [nio-8080-exec-4] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.transaction.UnexpectedRollbackException: Transaction silently rolled back because it has been marked as rollback-only] with root cause
org.springframework.transaction.UnexpectedRollbackException: Transaction silently rolled back because it has been marked as rollback-only
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:755) ~[spring-tx-5.1.6.RELEASE.jar:
As #thanhngo alread mentioned. This is how to do it.
You already have the correct annotation on the addUser method and any RuntimeException will cause the transaction to be rolled back.
Make sure that usersRespository.addUser... and authoritiesReposotory.addNew... also have the #Transactional annotation

App can't run from eclipse which created by 'jhipster --skipClient'

java.lang.IllegalStateException: Error processing condition on org.springframework.boot.autoconfigure.context.MessageSourceAutoConfiguration
at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:64)
at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:108)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader$TrackedConditionEvaluator.shouldSkip(ConfigurationClassBeanDefinitionReader.java:441)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:129)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:118)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:328)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:271)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:91)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:692)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:530)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:386)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
at com.einfochips.demo.TestApp.main(TestApp.java:63)
Caused by: java.lang.IllegalStateException: Failed to introspect Class [org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration] from ClassLoader [sun.misc.Launcher$AppClassLoader#659e0bfd]

Spring Cloud Config Zookeeper Exception

I am trying to use Spring cloud config with zookeeper for configuration management.
My build.gradle looks like:
dependencies {
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.cloud:spring-cloud-starter-zookeeper-config')
compile('org.springframework.cloud:spring-cloud-config-server')
}
Here is my bootstrap.properties file:
spring.application.name = myapp
spring.cloud.zookeeper.connectString: localhost:2181
This is the application class:
#SpringBootApplication
#EnableConfigServer
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}
But the application fails to launch and gives an exception:
Error starting Tomcat context.
Exception: org.springframework.beans.factory.BeanCreationException.
Message: Error creating bean with name 'servletEndpointRegistrar'
defined in class path resource
[org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration.class]
: Bean instantiation via factory method failed;
nested exception is org.springframework.beans.BeanInstantiationException
: Failed to instantiate [org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar]
: Factory method 'servletEndpointRegistrar' threw exception;
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'healthEndpoint'
defined in class path
resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]
: Bean instantiation via factory method failed;
nested exception is org.springframework.beans.BeanInstantiationException
: Failed to instantiate [org.springframework.boot.actuate.health.HealthEndpoint]
: Factory method 'healthEndpoint' threw exception;
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException
: Error creating bean with name 'configServerHealthIndicator'
defined in class path resource
[org/springframework/cloud/config/server/config/EnvironmentRepositoryConfiguration.class]
: Unsatisfied dependency expressed through
method 'configServerHealthIndicator' parameter 0;
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException
: Error creating bean with name 'org.springframework.cloud.config.server.config.CompositeConfiguration'
: Unsatisfied dependency expressed through method 'setEnvironmentRepos' parameter 0;
nested exception is org.springframework.beans.factory.BeanCreationException
: Error creating bean with name
'defaultEnvironmentRepository' defined in class path
resource [org/springframework/cloud/config/server/config/DefaultRepositoryConfiguration.class]
: Bean instantiation via factory method failed;
nested exception is org.springframework.beans.BeanInstantiationException
: Failed to instantiate
[org.springframework.cloud.config.server.environment.MultipleJGitEnvironmentRepository]
: Factory method 'defaultEnvironmentRepository' threw exception;
nested exception is java.lang.NullPointerException
What could be the reason behind this? Seems like it is searching for git repository even after specifying zookeeper.

Error creating bean with name 'dao'

i dont know ahy i got this error when i wanna test my app using spring beans this the main test :
public class Test {
public static void main(String[] args) {
ClassPathXmlApplicationContext context=
new ClassPathXmlApplicationContext(new String[]
{"applicationContext.xml"});
IBanqueMetier metier=(IBanqueMetier) context.getBean("metier");
metier.addClient(new Client("C1", "AD1"));
metier.addClient(new Client("C2", "AD2"));
}
and this the 1rst error :
Exception in thread "main"org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'dao': Injection of persistence dependencies
failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: Illegal attempt to map a non collection as a #OneToMany, #ManyToMany or #CollectionOfElements: org.gestion.bp.entities.Compte.employe
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessPropertyValues(PersistenceAnnotationBeanPostProcessor.java:342)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)
With Spring exceptions, it's important that you read the whole message up to the very end. I usually split the message into several lines to make it more readable:
Exception in thread "main"org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'dao': Injection of persistence dependencies failed;
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'entityManagerFactory' defined in class path resource [applicationContext.xml]:
Invocation of init method failed;
nested exception is org.hibernate.AnnotationException:
Illegal attempt to map a non collection as a #OneToMany, #ManyToMany or #CollectionOfElements:
org.gestion.bp.entities.Compte.employe
As you can see, you made an error in the definition of the field org.gestion.bp.entities.Compte.employe

Off Platform Sybase connection using Spring Boot and Cloud Foundry

I am trying to create an off-platform sybase connection in my application.
I am using Spring boot and have also created a user provided service at CF.
what extension classes would I need to create or use to achieve this ?
I have done oracle connection using OracleServiceInfo and OracleServiceInfoCreator class.
but there is no SybaseServiceInfo class.
Below are the details for the ups
{
"credentials": {
"hostname": "host",
"jdbcUrl": "jdbc:sybase://username:password#host:port/name",
"name": "name",
"password": "password",
"port": "port",
"uri": "sybase://username:password#host:port/name",
"username": "username"
},
"label": "user-provided",
"name": "SYBDB",
"syslog_drain_url": "",
"tags": []
}
I am new to CF. Any help would be great.
After looking into Scott Fredrick's reply I took below mentioned steps :
I have created a ServiceInfoCreator class and a ServiceInfo class as mentioned below:
ServiceInfoCreator
import java.util.Map;
import org.springframework.cloud.cloudfoundry.CloudFoundryServiceInfoCreator;
import org.springframework.cloud.cloudfoundry.Tags;
import org.springframework.context.annotation.Profile;
#Profile({ "cloud" })
public class SybaseServiceInfoCreator extends
CloudFoundryServiceInfoCreator<SQLDBServiceInfo> {
public SybaseServiceInfoCreator(Tags tags, String[] uriSchemes) {
super(new Tags(), "sybase");
// TODO Auto-generated constructor stub
}
#Override
public SQLDBServiceInfo createServiceInfo(Map<String, Object> serviceData) {
// TODO Auto-generated method stub
#SuppressWarnings("unchecked")
Map<String, String> credentials = (Map<String, String>) serviceData
.get("credentials");
String id = serviceData.get("name").toString();
String uri = credentials.get("uri");
return new SQLDBServiceInfo(id, uri);
}
}
ServiceInfo
import org.springframework.cloud.service.UriBasedServiceInfo;
public class SQLDBServiceInfo extends UriBasedServiceInfo {
public SQLDBServiceInfo(String id, String uriString) {
super(id, uriString);
// TODO Auto-generated constructor stub
}
}
and I made an entry in META-INF/Services/org.springframework.cloud.cloudfoundry.CloudFoundryServiceInfoCreator
com.x.y.SybaseServiceInfoCreator
but I get the below error when I push the application :
2015-04-20T16:28:59.85+0530 [App/0] ERR ... 190 more
2015-04-20T16:28:59.85+0530 [App/0] ERR Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.C
loud]: Factory method 'cloud' threw exception; nested exception is java.util.ServiceConfigurationError: org.springframework.cloud.CloudConnector: Provider or
g.springframework.cloud.cloudfoundry.CloudFoundryConnector could not be instantiated
2015-04-20T16:28:59.85+0530 [App/0] ERR at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrat
egy.java:189)
2015-04-20T16:28:59.85+0530 [App/0] ERR at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorRes
olver.java:588)
2015-04-20T16:28:59.85+0530 [App/0] ERR ... 202 more
2015-04-20T16:28:59.85+0530 [App/0] ERR Caused by: java.util.ServiceConfigurationError: org.springframework.cloud.CloudConnector: Provider org.springframew
ork.cloud.cloudfoundry.CloudFoundryConnector could not be instantiated
2015-04-20T16:28:59.85+0530 [App/0] ERR at java.util.ServiceLoader.fail(ServiceLoader.java:232)
2015-04-20T16:28:59.85+0530 [App/0] ERR at java.util.ServiceLoader.access$100(ServiceLoader.java:185)
2015-04-20T16:28:59.85+0530 [App/0] ERR at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:384)
2015-04-20T16:28:59.85+0530 [App/0] ERR at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
2015-04-20T16:28:59.85+0530 [App/0] ERR at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
2015-04-20T16:28:59.85+0530 [App/0] ERR at org.springframework.cloud.CloudFactory.scanCloudConnectors(CloudFactory.java:91)
2015-04-20T16:28:59.85+0530 [App/0] ERR at org.springframework.cloud.CloudFactory.<init>(CloudFactory.java:35)
2015-04-20T16:28:59.85+0530 [App/0] ERR at com.x.y.config.CloudAdminConfig.cloud(CloudAdminConfig.java:56)
2015-04-20T16:28:59.85+0530 [App/0] ERR at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2015-04-20T16:28:59.85+0530 [App/0] ERR at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
2015-04-20T16:28:59.85+0530 [App/0] ERR at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
2015-04-20T16:28:59.85+0530 [App/0] ERR at java.lang.reflect.Method.invoke(Method.java:483)
2015-04-20T16:28:59.85+0530 [App/0] ERR at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrat
egy.java:162)
2015-04-20T16:28:59.85+0530 [App/0] ERR ... 203 more
2015-04-20T16:28:59.85+0530 [App/0] ERR Caused by: java.util.ServiceConfigurationError: org.springframework.cloud.cloudfoundry.CloudFoundryServiceInfoCreat
or: Provider com.x.y.config.SybaseServiceInfoCreator could not be instantiated
2015-04-20T16:28:59.85+0530 [App/0] ERR at java.util.ServiceLoader.fail(ServiceLoader.java:232)
2015-04-20T16:28:59.85+0530 [App/0] ERR at java.util.ServiceLoader.access$100(ServiceLoader.java:185)
2015-04-20T16:28:59.85+0530 [App/0] ERR at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:384)
2015-04-20T16:28:59.85+0530 [App/0] ERR at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
2015-04-20T16:28:59.85+0530 [App/0] ERR at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
2015-04-20T16:28:59.86+0530 [App/0] ERR at org.springframework.cloud.AbstractCloudConnector.scanServiceInfoCreators(AbstractCloudConnector.java:53)
2015-04-20T16:28:59.86+0530 [App/0] ERR at org.springframework.cloud.AbstractCloudConnector.<init>(AbstractCloudConnector.java:33)
2015-04-20T16:28:59.86+0530 [App/0] ERR at org.springframework.cloud.cloudfoundry.CloudFoundryConnector.<init>(CloudFoundryConnector.java:32)
2015-04-20T16:28:59.86+0530 [App/0] ERR at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
2015-04-20T16:28:59.86+0530 [App/0] ERR at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
2015-04-20T16:28:59.86+0530 [App/0] ERR at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
2015-04-20T16:28:59.86+0530 [App/0] ERR at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
2015-04-20T16:28:59.86+0530 [App/0] ERR at java.lang.Class.newInstance(Class.java:438)
2015-04-20T16:28:59.86+0530 [App/0] ERR at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:380)
2015-04-20T16:28:59.86+0530 [App/0] ERR ... 213 more
2015-04-20T16:28:59.86+0530 [App/0] ERR Caused by: java.lang.InstantiationException: com.x.y.config.SybaseServiceInfoCreator
2015-04-20T16:28:59.86+0530 [App/0] ERR at java.lang.Class.newInstance(Class.java:423)
2015-04-20T16:28:59.86+0530 [App/0] ERR at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:380)
2015-04-20T16:28:59.86+0530 [App/0] ERR ... 224 more
2015-04-20T16:28:59.86+0530 [App/0] ERR Caused by: java.lang.NoSuchMethodException: com.x.y.config.SybaseServiceInfoCreator.<init>()
2015-04-20T16:28:59.86+0530 [App/0] ERR at java.lang.Class.getConstructor0(Class.java:3074)
2015-04-20T16:28:59.86+0530 [App/0] ERR at java.lang.Class.newInstance(Class.java:408)
2015-04-20T16:28:59.86+0530 [App/0] ERR ... 225 more
2015-04-20T16:29:02.38+0530 [DEA] OUT Instance (index 0) failed to start accepting connections
2015-04-20T16:29:02.39+0530 [API] OUT App instance exited with guid e946c9db-afdc-459a-bd01-ff718a5900db payload: {"cc_partition"=>"default", "droplet"=>
"e946c9db-afdc-459a-bd01-ff718a5900db", "version"=>"aeb7dbc8-e856-445b-80f1-0ff56339e1f5", "instance"=>"3efe1b541e2a4c6eb6aaecd7daac1143", "index"=>0, "reaso
n"=>"CRASHED", "exit_status"=>1, "exit_description"=>"app instance exited", "crash_timestamp"=>1429527542}
Not sure what I am messing up.
There's also a warning that it cannot find the ServiceInfoCreator in the beginning
2015-04-20T18:04:59.98+0530 [App/0] OUT 2015-04-20 12:34:59.988 WARN 33 --- [ main] o.c.r.o.s.cloud.AbstractCloudConnector : No suitable servi
ce info creator found for service SYBDB Did you forget to add a ServiceInfoCreator?
Spring Cloud Connectors is the project that provides the OracleServiceInfo and OracleServiceInfoCreator classes that you mentioned. As you've said, Spring Cloud Connectors doesn't support Sybase database connections. So, you have two choices:
1) Extend Spring Cloud Connectors to support Sybase connections via a user-provided service. Documentation on writing such an extension can be found here and here. These extension classes can be in your project or in a separate library, they don't need to be a part of the core SCC project for you to use them.
2) Use the vcap properties that Spring Boot automatically adds to the environment when it detects that an app is running on Cloud Foundry. You could do something as simple as including a #Value("${vcap.services.sybase.credentials.jdbcUrl}") annotation on a Spring bean and use that value to create a DataSource bean. See here for more details.
The second choice is far simpler, and is a good place to start. If you just have one application that will use this type of connection then this might suffice. If you need to use this type of connection in multiple apps then writing the SCC extension in the first option and making that a re-usable library would be a better option.
Thanks.That seemed to be the problem.
This is how I created my classes now
ServiceInfoCreator
#Profile({ "cloud" })
public class SybaseServiceInfoCreator extends
RelationalServiceInfoCreator<SybaseServiceInfo> {
public SybaseServiceInfoCreator() {
super(new Tags(), "sybase");
}
#Override
public SybaseServiceInfo createServiceInfo(String id, String uri) {
// TODO Auto-generated method stub
return new SybaseServiceInfo(id, uri, "sybase");
}
}
ServiceInfo
#Profile({ "cloud" })
#ServiceInfo.ServiceLabel("sybase")
public class SybaseServiceInfo extends RelationalServiceInfo {
public SybaseServiceInfo(String id, String url, String uri) {
super(id, validateUrl(url), uri);
}
private static String validateUrl(String url) {
if (parse(url).getHost() == null) {
throw new IllegalArgumentException("The URL " + url
+ " does not appear to contain a hostname - are you missing a trailing slash?");
}
return url;
}
private static URI parse(String url) {
try {
return new URI(url);
} catch (URISyntaxException e) {
throw new IllegalArgumentException(e);
}
}
#Override
public String getJdbcUrl() {
return String.format("jdbc:%s:Tds:%s:%d/%s",
jdbcUrlDatabaseType,getHost(), getPort(), getPath());
}
}