title: How do I run a single JVM with multiple spring boot applications?
body: <p>Lets say I have 25 spring boot micro-services each of which starts with 1GB JVM in production. At any given time not all are in use and there is no instance when they are using the full 25GB memory at once. In reality many of them will sit idle 90% of the time but any of them might at some point get called and require up to 1GB memory.</p>
  
  <p>In my development environment I would like to run all of them at once but only have 8GB memory. I don't need great performance but I need them all to run at the same time for the entire app to work. I would like to try to run all the applications within a single JVM with 6GB dedicated memory. That should be enough at any given time.</p>
  
  <p>This seems like it would be a common issue as many companies are converting to cloud/microservices. 10 years ago we would have one monolithic app with single JVM (easy to run in dev environment). Now we have dozens of small apps which might not need a ton of memory but they each run in their own JVM so each has a good amount of overhead. This actually makes development more complex rather than simplifying. So Im trying to find a solution for our developers where they can run everything but not kill the memory on their machines. </p>
  
  <ul>
  <li>The spring boot apps need to run without modification aside from
  maybe local profiles. Otherwise developers would have to make tons of changes every time they pull the code from git</li>
  <li>Each project needs to be able to configure a different port (application-local.properties setting)
  for tomcat.  </li>
  <li>Each project needs its own classpath entries (for instance one might use version 1.0 of a jar and another might use version 2.0 and without separate classpaths one or the other would break)</li>
  </ul>
  
  <p>I have been trying to follow this <a href="https://www.davidtanzer.net/david&#39;s%20blog/2015/04/01/running-multiple-spring-boot-apps-in-the-same-jvm.html" rel="nofollow noreferrer">post</a> but its not 100% what I want. I feel like a proper solution should respect the application.properties / application-local.properties file and use the port set inside the project rather than having to hardcode any configuration outside the project. Essentially his post is starting a separate thread for each microservice and attaching a separate classloader to each thread. Then calling SpringApplication.run and passing in the classname that would normally be used to start the microservice. I think this is maybe ignoring the auto configuration properties.</p>
  
  <p>Any help would be greatly appreciated!     </p>