Reputation: 289
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?
Upvotes: 3
Views: 3681
Reputation: 4598
If you have the code for both,
Dont need the code, just include the class names (by scanning the jars or asking the dev team) Can make a new main method that scans all the packages and adds them to the context. Then start that method. I think it will scan all jars in class path. So even if your new main method is in one jar it will scan classes in the other jar. That way wont have to repack to one jar.
This is one way to keep one JVM and one port.
The proxy method suggested by Timir is fine too. Instead of a Java microservice I will suggest use Nginx or apache web server for composing, Run the two Java processes in a different system or different port if same system as the web server.
Upvotes: 0
Reputation: 13974
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.
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.
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.
Upvotes: 2
Reputation: 1425
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.
Upvotes: 1