java 在一个 jvm 中运行多个 spring boot jar
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31624643/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Run multiple spring boot jars in one jvm
提问by Sean Liang
My project contains several services, each one is annotated with @SpringBootApplication and can be run on a random port via "gradle bootRun".
我的项目包含多个服务,每个服务都用@SpringBootApplication 进行注释,并且可以通过“gradle bootRun”在随机端口上运行。
Is it possible to build the services into jars and run them together in one JVM? Not matter by programmatic method or just put them in a container.
是否可以将服务构建到 jars 中并在一个 JVM 中一起运行它们?无论是通过编程方法还是将它们放入容器中。
Please show me some instructions if possible. Thanks!
如果可能,请给我一些说明。谢谢!
回答by David Tanzer
It's a little hacky, but can be done. I wrote a blog post about it some time ago: Running Multiple Spring Boot Apps in the Same JVM. The basic idea is to run every Spring Boot application in a different classloader (because otherwise there would be resource conflicts).
这有点hacky,但可以做到。前段时间我写了一篇关于它的博客文章:在同一 JVM 中运行多个 Spring Boot 应用程序。基本思想是在不同的类加载器中运行每个 Spring Boot 应用程序(否则会出现资源冲突)。
I, personally, only used it for testing. I would prefer to run the different applications in different docker containers in production. But for testing it's pretty cool: You can quickly boot up your application and debug everything...
我个人仅将其用于测试。我更愿意在生产中的不同 docker 容器中运行不同的应用程序。但是对于测试来说,它非常酷:您可以快速启动应用程序并调试所有内容......
回答by Rameez Shikalgar
If you want to launch multiple spring boot microservices in single JVM then you can achieve this by launching multiple threads. Please refer sample code here https://github.com/rameez4ever/springboot-demo.git
如果您想在单个 JVM 中启动多个 Spring Boot 微服务,那么您可以通过启动多个线程来实现。请在此处参考示例代码https://github.com/rameez4ever/springboot-demo.git
回答by iamiddy
Yes you can please check this SO.
是的,你可以请检查这个SO。
However, if separating the running-user processes and simplicity is core , I would recommend the use of Docker containers, each running instance of the container(your apps) will runs in its own JVM on the same or distributed host
但是,如果分离运行用户进程和简单性是核心,我建议使用Docker 容器,容器的每个运行实例(您的应用程序)将在同一或分布式主机上的自己的 JVM 中运行