简体   繁体   English

将spring boot应用程序添加为另一个Spring启动应用程序的依赖项

[英]Add spring boot application as dependency to another spring boot application

I have a spring boot application A which is a spring data service to do some CRUD operations. 我有一个spring boot应用程序A,它是一个弹簧数据服务,用于执行一些CRUD操作。 Now I wanted to add this A as dependency to another Spring boot application B which is just a rest service to access various methods of A. When I did that and started B's Application class, I see the application A getting run and all the configurations are done and stops. 现在我想将此A作为依赖项添加到另一个Spring引导应用程序B,它只是一个访问A的各种方法的休息服务。当我这样做并启动B的Application类时,我看到应用程序A正在运行,所有配置都是完成并停止。 What I wanted to achieve is application B should run a tomcat on pot 8080 so that I could access application B's CRUD methods. 我想要实现的是应用程序B应该在pot 8080上运行tomcat,以便我可以访问应用程序B的CRUD方法。 Could someone please help me to achieve this? 有人可以帮助我实现这个目标吗?

Before writing this question I did search the forum for all relevant threads but could not find a solution. 在写这个问题之前,我确实在论坛上搜索了所有相关的线程,但找不到解决方案。

I have a spring boot application A which is a spring data service to do some CRUD operations. 我有一个spring boot应用程序A,它是一个弹簧数据服务,用于执行一些CRUD操作。 Now I wanted to add this A as dependency to another Spring boot application B which is just a rest service to access various methods of A. 现在我想将此A作为依赖项添加到另一个Spring启动应用程序B,它只是一个访问A的各种方法的休息服务。

According to the described need, I am not sure you need to have two Spring Boot applications. 根据描述的需要,我不确定你需要两个Spring Boot应用程序。
Having two distinct Spring Boot web based applications assumes that the two applications need to be physically separated. 有两个不同的Spring Boot基于Web的应用程序假定这两个应用程序需要在物理上分开。 This separation has a cost since you have to make a way to allow the applications to communicate between them : webservice, jms, rmi, jms, etc... and you have to develop and maintain two Spring Boot applications, but you said that 这种分离有成本,因为你必须让一种方法允许应用程序在它们之间进行通信:webservice,jms,rmi,jms等...你必须开发和维护两个Spring Boot应用程序,但你说的是

Spring boot application B which is just a rest service to access various methods of A Spring启动应用程序B,它只是一个访问A的各种方法的休息服务

If you want to call repository methods of A in a straight way from rest services of B , why having two distinct applications and make it more complex ? 如果要直接从B其他服务调用A存储库方法,为什么要有两个不同的应用程序并使其更复杂?
A single Spring Boot application with multiple modules could be more suitable and maintainable solution: 具有多个模块的单个Spring Boot应用程序可能是更合适和可维护的解决方案:

- parent-my-app (super and parent project)
|
|----> repository-my-app module
|     
|   
|----> rest-my-app module    
                    |----> dependency on repository-my-app module  

To conclude, strongly decoupling the communication between two layers via two applications has a cost and coping with two Spring Boot application too. 总而言之,通过两个应用程序强烈地解耦两层之间的通信需要花费成本并且还要处理两个Spring Boot应用程序。
So, if you don't really need it, you should avoid. 所以,如果你真的不需要它,你应该避免。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM