How to run 2 servers as separate processes?

J_Strauton :

I have 2 services and each has a controller.

@Service
public class Service1
{
}

@RestController
@RequestMapping("/api")
public class Controller1
{
}

...

@Service
public class Service2
{
}

@RestController
@RequestMapping("/api")
public class Controller2
{
}

I would like to run each service or controller in their own process. How can I do this without creating two apps?

This is similar to what I want, see image below: enter image description here

Arthur Gurov :

Considering the attached components diagram, I would suggest looking into microservices architecture. You will be able to separate responsibilities by domains (movie, customer, review) and even build separate access rules (e.g. anonymous access for movies catalog and secured access to customer data). Each data storage (DB1, DB2, etc.) will be linked to the responsible service only. In addition, you will be able to scale exactly the necessary services depending on usage e.g. 5 movie services, 2 customer data services, and 3 review services.

Gradle or Maven will easily allow you to build a big project with multiple sub-modules. Some of your modules will be application modules and some of them will be shared modules (models, utils, etc.).

In addition, I would recommend to set up a separate repo for each project in order to simplify change management and review - it will be very helpful on a big scale.

Example Gradle structure:

Root module

  • models
  • utils
  • movie service
  • customer service
  • review service

Each service sub-module will contain its own @SpringBootApplication with controllers, services and repositories. Of course, you will need to add Spring Boot Gradle plugin to each service sub-module.

Update: Going forward, it would be wise to add Docker configuration to each service sub-module and run each application as a Docker container. Docker will significantly simplify the development.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=109413&siteId=1