Add a database to store the catalog. Expose the repository as RESTful webservices.

Technologies used

  1. Spring Boot
  2. MongoDB
  3. spring-data-mongodb
  4. spring-data-rest

MongoDB integration

  • 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

Source Code

Tag “step2” in repository: catalog-service

git clone https://github.com/microxs-demo/catalog-service
cd catalog-service
git checkout tags/step2


Detailed explanation in video