Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deploy 2 microservices from 2 different jars into same port in spring boot

I'm new to Spring Boot. I have deployed a microservice into port 80 in some server. This service has URL pattern root as '/test'.

Then I will have to deploy another microservice into same port in this same server. Its URL pattern is '/test2' from another different jar.

Is it possible to deploy 2 different jars that point to 2 different URLs into same port?

like image 761
Luís Palma Avatar asked Dec 19 '25 09:12

Luís Palma


2 Answers

There’s two different ways to sort of do this:

1, The already mentioned way of using a proxy in front of the services, so users think they are running the same port, but really not. Nginx has a nifty proxy feature for this, and Netflix’s Eureka is 20% this too.

  1. Build your two Spring applications as .war files, and deploy them to an application server like (non-embedded) Tomcat. There’s a good blog article on how to generate a .war and deploy it to a standalone Tomcat.

  2. Put the two services in seperate Docker containers. (But you’ll still need to EXPOSE different ports to the outside world, so this answer is kind of cheating.

Option 2 is probably closest, and you’re still in Javaland... but it’s not the hip new way to deploy things in Spring Boot land in 2018.

like image 73
RyanWilcox Avatar answered Dec 21 '25 22:12

RyanWilcox


Have a third microservice as proxy for the other two. Forward requests to them based on request content, context, URL pattern or anything suitable to your specific application.

like image 42
Timir Avatar answered Dec 21 '25 22:12

Timir



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!