Using the persistence layer in the service layer
In this section, we will learn how to use the persistence layer in the service layer to store and retrieve data from a database. We will go through the following steps:
- Logging the database connection URL
- Adding new APIs
- Calling the persistence layer from the service layer
- Declaring a Java bean mapper
- Updating the service tests
Logging the database connection URL
When scaling up the number of microservices where each microservice connects to its own database, it can be hard to keep track of what database each microservice actually uses. To avoid this confusion, a good practice is to add a log statement directly after the startup of a microservice that logs connection information that is used to connect to the database.For example, the startup code for the product
service looks like this:
public class ProductServiceApplication {
private static final Logger LOG =
LoggerFactory.getLogger(ProductServiceApplication.class);
public...