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 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.
Participation of this paper Tencent cloud media sharing plan , You are welcome to join us , share .