前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >SpringCloud database connection debug

SpringCloud database connection debug

作者头像
Jerry Wang
发布2021-02-23 17:17:49
4450
发布2021-02-23 17:17:49
举报

Created by Wang, Jerry, last modified on Aug 08, 2016

The environment variable VCAP_SERVICES is used by Cloud Foundry to provide access information to all backing services, including database connection information to microservices. With this information, and the following plugins making use of it, a database connection can be created and used. Locally we configure this same environment variable so that a dedicated database can be used for local tests.

We use the CloudDatabaseConfig file to configure access to a database. Starting with the information provided in the environment variable VCAP_SERVICES , we end up with an instance of a CRUD repository. For this the three plugins are used, which are explained in detail below. As the CloudDatabaseConfig class is registered in the ContextListener class, also the beans defined using methods annotated with @Bean are registered in the context.

EclipseLink

EclipseLink is used as a JPA implementation. JPA/EclipseLink is used to map from Java classes to database tables (and from Java data types to SQL data types). SQL queries, result set handling, and object conversion are managed and optimized by JPA/EclipseLink. Applications using EclipseLink are portable to supported SQL databases with little performance overhead. An alternative to EclipseLink is Hibernate (also see this discussion).

EclipseLink needs access to a database, which we provide using the DataSource instance of the previous step. Using this database connection, the JPA object instances (EntityManager and TransactionManager) are provided. This is done with the following code, where most functionality is part of EntityManagerFactoryProvider. Again, the two defining methods are annotated with @Bean so that the corresponding beans are registered automatically.

clipboard3.png
clipboard3.png
clipboard4.png
clipboard4.png
clipboard5.png
clipboard5.png
clipboard6.png
clipboard6.png
clipboard7.png
clipboard7.png
clipboard1.png
clipboard1.png
clipboard2.png
clipboard2.png
clipboard3.png
clipboard3.png
clipboard4.png
clipboard4.png
clipboard5.png
clipboard5.png
clipboard6.png
clipboard6.png
clipboard7.png
clipboard7.png
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2020-03-13 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Created by Wang, Jerry, last modified on Aug 08, 2016
  • EclipseLink
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档