0
votes

Trying to deploy springboot project in cloud foundry. Getting the below error.

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'entityManagerFactoryBuilder' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Unsatisfied dependency expressed through method 'entityManagerFactoryBuilder' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaVendorAdapter' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.orm.jpa.JpaVendorAdapter]: Factory method 'jpaVendorAdapter' threw exception; nested exception is java.lang.RuntimeException: Driver com.microsoft.sqlserver.jdbc.SQLServerDriver claims to not accept jdbcUrl, ${vcap.services.xxx.credentials.jdbcUrl}

application.properties

spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.jpa.show-sql=true
spring.jpa.hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect

spring.datasource.url=${vcap.services.xxx.credentials.jdbcUrl}
spring.datasource.username=${vcap.services.xxx.credentials.username}
spring.datasource.password=${vcap.services.xxx.credentials.password}

build.gradle

implementation 'org.springframework.boot:spring-boot-starter-web'

//cloud connector
implementation 'org.springframework.boot:spring-boot-starter-cloud-connectors'

//database
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'


implementation group: 'org.springframework.boot', name: 'spring-boot-starter-jdbc'

implementation group: 'com.microsoft.sqlserver', name: 'mssql-jdbc'

compile group: 'org.springframework.cloud', name: 'spring-cloud-cloudfoundry-connector'

Expected : should be deployed and running Actual : Error in the title

1

1 Answers

0
votes

You should remove the 'org.springframework.boot:spring-boot-starter-cloud-connectors' and group: 'org.springframework.cloud', name: 'spring-cloud-cloudfoundry-connector' dependencies from the project.

When Spring Cloud Connectors jars are on the classpath, they will create connection beans for the services detected in VCAP_SERVICES (e.g. a Datasource bean in your case). Because Connectors is creating the connection beans instead of Spring Boot, your spring.datasource properties are ignored. Removing Connectors from the project will allow Boot to create the connections using your properties.

Alternatively, you could choose to use Java CFEnv to set the spring.datasource properties automatically from VCAP_SERVICES (once Connectors is removed from the project).