No unique service maching interface error in Spring Boot Cloud Foundry error

后端 未结 2 2094
情话喂你
情话喂你 2021-01-24 22:59

I am trying to follow this tutorial https://github.com/cf-platform-eng/spring-boot-cities/tree/master/cities-service to run my spring boot application in Cloud Foundry. I have l

相关标签:
2条回答
  • 2021-01-24 23:01

    If you include spring-boot-starter-cloud-connectors as a dependency, then Spring Cloud Connectors will attempt to create the java.sql.DataSource bean necessary to connect to the database. Connectors does this by looking for a service binding that has certain characteristics. The No unique service matching interface javax.sql.DataSource found message means that Connectors couldn't find a service binding of the appropriate type.

    If you want to use Connectors as in that sample app then you will need to create a user-provided service instance with the details of the Postgres connection and bind that service instance to the app.

    Alternatively, you could remove the spring-boot-starter-cloud-connectors dependency and instead configure the database connection using spring.datasource properties in application.yml.

    These options are explained in more detail in a blog post.

    0 讨论(0)
  • 2021-01-24 23:13

    Just to summarize the overall solution for other readers.

    If you have a scenario where you want to have a spring boot application talk to a database (hosted in other machine) and then run the application from cloud foundry. Then follow some of the tips below.

    1. Once you deploy your Spring Boot application and want to use Spring Boot cloud connector make sure you have all the proper dependencies in your classpath (spring-boot-cloud-connector and jar.
    2. If you want to bind a service instance with the application .Make sure the credentials adhere to this specification http://cloud.spring.io/spring-cloud-connectors/spring-cloud-cloud-foundry-connector.html#_postgresql
    3. In the service instance parameters make sure you use the uri parameter not depend on the username and password to construct the uri
    4. Make sure your database instance is actually running and you have created application service groups to allow outbound communication from your cloud foundry app. https://docs.cloudfoundry.org/concepts/asg.html#viewing

    Steps 3 and 4 were the mistakes i made. Once corrected the application works fine.

    Best Regards, Saurav

    0 讨论(0)
提交回复
热议问题