简体   繁体   English

最佳实践:部署Angular App和Spring REST Api

[英]Best Practice:Deploying Angular App and Spring REST Api

I'm trying to deploy an angular application which communicates with a spring rest api. 我正在尝试部署一个与spring rest api通信的有角度的应用程序。

The spring application is hosted on tomcat, and working as expected. spring应用程序托管在tomcat上,并且可以正常运行。

My angular app is a simple form, which also works in theory. 我的角度应用程序是一种简单的形式,在理论上也可以使用。 Now I attempt to deploy both on my local system, and have the angular post data send to the tomcat server, where it will be handled by the spring app. 现在,我尝试将它们都部署在本地系统上,并将有角度的发布数据发送到tomcat服务器,该服务器将在其中由spring应用程序处理。

As this will be something I will develop continually over the next months, I am looking for advices on the best practices on deployment. 由于这将在接下来的几个月中不断发展,因此我正在寻找有关部署最佳实践的建议。 Is it recommended to serve both from the tomcat container, or should there be a separation of concerns? 是否建议同时从tomcat容器中进行服务,还是应该分开关注? I am also hoping to learn about scalability and architectures with this experiment, so using seperate vms, multiple servers, load balancing etc I am keen to understand and receive any helpful advice or pointers in the right direction. 我也希望通过此实验了解可伸缩性和体系结构,因此使用单独的vms,多个服务器,负载平衡等,我很想了解并获得正确方向的任何有用建议或指示。 Thank you. 谢谢。

Separation of the user interface from the core business logic (backend) is a good choice if you expect your application to scale substantially (more services, frequent changes). 如果您希望应用程序能够大规模扩展(更多服务,频繁更改),则将用户界面与核心业务逻辑(后端)分开是一个不错的选择。

You took the first step right. 您迈出了第一步。

Here is what is my experience and what I can safely say as the "recommended" setup: 这是我的经验,我可以放心地说“推荐”设置:

  • Angular application and Spring based REST application are two disparate components of your web application. Angular应用程序和基于Spring的REST应用程序是Web应用程序的两个完全不同的组件。 They are developed around different contexts of concerns. 它们是围绕不同的关注环境而开发的。 You will be able to maintain them well without breaking your whole application if you handle (develop, build and deploy) them separately. 如果您分别处理(开发,构建和部署)它们,则可以很好地维护它们而不会破坏整个应用程序。

  • Separating out the user interface from the core business logic also helps you to use different technology stack for different purposes. 将用户界面与核心业务逻辑分开,还可以帮助您将不同的技术堆栈用于不同的目的。 What works better for building UI may not for backend or vice versa 什么对构建UI更有效,但可能不适用于后端,反之亦然

  • You mentioned that these components will continually evolve. 您提到这些组件将不断发展。 Usually, they evolve separately. 通常,它们是分开发展的。 This is a best case for separate deployment pipelines (to build and deploy them separately). 对于单独的部署管道(分别构建和部署),这是最好的情况。

  • The Angular application could be hosted on node server while Spring based backend API runs on a Tomcat instance. Angular应用程序可以托管在node服务器上,而基于Spring的后端API在Tomcat实例上运行。 This will also help you to load balance these components separately based on which component needs more attention. 这还将帮助您根据需要更多关注的组件分别对这些组件进行负载平衡。

  • Due to this separation, the complete application does not go down during downtime. 由于这种分离,整个应用程序在停机期间不会停机。 REST APIs could be down for maintenance or due to a fault but the application's UI may still be up and serving some requests which do not depend on the backend. REST API可能出于维护目的或由于故障而关闭,但应用程序的UI可能仍处于启动状态,并且正在处理一些不依赖于后端的请求。 This is far better than the application not being available at all. 这比根本不可用的应用程序要好得多。

  • Techniques like feature toggles could be employed at the UI layer to disable some part of the functionality which depends on the backend or is half done. 可以在UI层使用诸如功能切换之类的技术来禁用部分功能,具体取决于后端或完成一半。 Though it is possible to do that in a single deployable application, it is much cleaner to understand and manage when the UI is separated out from the backend logic. 尽管可以在单个可部署的应用程序中执行此操作,但是当UI与后端逻辑分离时,更易于理解和管理。 The backend could have its own feature toggle framework (different than the one at the UI layer). 后端可以有自己的功能切换框架(不同于UI层的框架)。

  • In future, you could open up the REST APIs to the outer world (or other applications) and add more services which may not be required for your Angular application. 将来,您可以向外界(或其他应用程序)开放REST API,并添加Angular应用程序可能不需要的更多服务。 Potentially, a dedicated team may work on the REST APIs component in the setup and it may make sense not to expose them to the Angular code. 潜在地,一个专门的团队可能会在设置中的REST API组件上工作,并且不将它们公开给Angular代码可能很有意义。

  • My favourite: treat the public facing Angular component of your application as a "client" for your Spring app (REST APIs). 我的最爱:将应用程序的面向公众的Angular组件视为Spring应用程序(REST API)的“客户端”。 This makes the REST application "generic" and loosely coupled with the Angular component which has huge advantages in the long run. 这使得REST应用程序是“通用的”,并且松散地与Angular组件耦合,从长远来看,Angular组件具有巨大的优势。

Having said that, it is okay to start with a single deployment for both during the initial phases however you must be ready to extract out the components at the first chance. 话虽如此,在初始阶段都可以从单个部署开始,但是您必须准备好在第一时间提取组件。

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

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