Add a database to store the catalog. Expose the repository as RESTful webservices.
- Spring Boot
- I have chosen MongoDB as the database for our catalog microservice.
- spring-data-mongodb module helps us integrate our application with mongodb by providing us with a POJO based entity model, and also allowing us to write repository style data access layer easily. The new dependency we introduced to our project is: –
- We created our catalog service’s entities which map to mongo db documents. They are annotated with @Document annotation.
- MongoDB connection properties are configured in catalog-service.yml
- We also created repositories (MongoRepository) for all entities that we want to expose.
- Enable Mongo Repositories using annotation: –
Expose repositories as RESTful services
- Next, we expose our repositories as RESTful services using spring-data-rest module. For this, we included the dependency: –
- Base Path for the RESTful services are also configured in catalog-service.yml
git clonecd catalog-service git checkout tags/step2
Detailed explanation in video