Search code examples
restspring-bootmicroservices

Spring : expose embedded JAR as another REST API


I have a monolithic Spring boot application that exposes a REST API /getUserList.

Now we are taking the micro service approach, so that we extracted some business code and create /getCountry microservice REST API.

Normally, /getUserList should call /getCountry to get all countries.

Now for testing purpose, I want to use these two REST API in the same server, but separately. What I can think of is to create two seperate JAR and let one call another. I want to know what is the right way to do this :

Should I list /getCountry as a module of /getUserList? Or should I create a separate project ?


Solution

  • You decided to break your monolith into microservices. You started on the right foot, separating the application logic based on the bounded contexts you defined. In this case you describe "countries" context and the "user" context.

    Microservices are independently deployable, so you are correct, they have to be separate jars. Your "user" service will call the "countries" service via the network as usual in microservices architecture.

    Usually, each microservice has their own repo (project), so that developers who have to work on the service, do not need to familiarize with a large codebase, or figure out why code not related to their service (bounded context) is there.

    That being said, if currently your project is quite small you can decide to keep these as separate modules (do not import countries module in the user module) under the same project and break them later.