have different ports and other dependencies. Running an instance of each of them on a local machine for development is heavy on system resources. My understanding is that each of these springboot apps will have a seperate JVM instance.
Is there any way to run them as a single app so that all of them will run on a single JVM instance ?
Isn't that just a monolith with extra steps?
In a way! This is not intended for deployment, just for reducing system resource usage in local environment...
I don't know Java, but in theory it should just be enough to import the root of each service from another file?
One similar solution I tried was to create a new application and add each of the seperate services as dependencies. Added component scan paths and exposed multiple ports on the server as per each services requirement. The services could communicate with each other as expected but the issue is, 1, same endpoint paths exist in these services 2, any of those endpoints can be accessed from any of those ports. 3, beans with same names exists across these services - renaming them is not ideal. So that solution was not adoptable in my case.
The services don't take independent port numbers? Is this a problem of port number for each service being assigned by the same env var, for example?
I don't think so.. simply what I did was just add all the endpoints from the services into a new app that has multiple ports exposed...they are on the single embedded server. Not the right solution, I realised 😅
You'll likely need to create a SpringApplication instance per service
Na you need to make them into jar files so they can be imported as deps
This is possible as long as all your microservices are OK to run on the same *version* of java/jvm. You'll need to run them somehow in individual class loaders. Suggested article at a galnce seems to suggest exactly that. But I would recommend you entirely different approach - don't do this. You'll waste tons of time on setting up the system that has never been intended to be set up this way. You'll have to write all that glue code and maintain it. Depending on whether your services are in a single repo, or they are each in a separate repo, this glue code can be quite complex. Also depending on the repo structure, it may be cumbersome to pull latest upstream. Also you may face bugs/limitations that are not obvious (e.g. some library may use native code which does not support to be shared between multiple class loaders). Just answer yourself - why do you need to run all the services at once on your machine? I never ever had a single reason to do that in my entire experience. I'm 99.99% sure you have dev environment, right? Just run one or two services that you need from you local, and the rest - in dev environment. And connect your local running services to those remotely running services in dev env. Even if you're developing some feature that affects many services, you still are not doing it in all the services at once. You'll do it one after another. So services that are done - just deploy them in dev off you feature branch.
Обсуждают сегодня