How can we run same spring boot application on multiple port on the same machine?

How can we run same spring boot application on multiple port on the same machine?


0






Rahul Kumar (@rahul)

We often don’t need to run multiple instances of our spring boot application on the same machine but learning them would be quite interesting.

I am assuming that you know about spring boot!.  

Why do we need to run spring app on multiple ports?

  • Load Balancing Testing
  • Distributed Computing Testing
  • Parallel developments environment on same machine by different users(Mostly used in small team)
  • Isolation and Versioning

How can we run it?

Using Command Line

First, you need to open a terminal at the root of your application. Once you have opened the terminal type the following. 

      mvn spring-boot:run -Dspring-boot.run.arguments=--server.port=8080
    

You can change 8080 to your desired port number.

Using Random Port

Open application.properties and add the following

      # application.properties
server.port=0
    

Setting server.port=0 will start the spring boot application on a random port. You can easily get the port number from logs.

      LiveReload server is running on port 35729
Tomcat started on port(s): 65449 (http) with context path ''
    

As you can see the port number 65449 has been printed on the terminal. Which can be used further to make HTTP requests. 

Add a thoughtful comment...

✨ Explore more tech insights and coding wonders with @dsabyte! Your journey in innovation has just begun. Keep learning, keep sharing, and let's continue to code a brighter future together. Happy exploring! 🚀❤️

  • #java
  • #backend
  • #spring-boot
  • #http
  • #port

Subscribe to our newsletter.

Join the "News Later" community by entering your email. It's quick, it's easy, and it's your key to unlocking future tech revelations.

Weekly Updates

Every week, we curate and deliver a collection of articles, blogs and chapters directly to your inbox. Stay informed, stay inspired, and stay ahead in the fast-paced world of technology.

No spam

Rest assured, we won't clutter your inbox with unnecessary emails. No spam, only meaningful insights, and valuable content designed to elevate your tech experience.

© 2024 @dsabyte. All rights reserved