简体   繁体   English

Spring boot + Angular应用程序正在运行

[英]Spring boot + Angular application working

I am new to Angular 7. I want to build Spring Boot+ Angular 7 application but I confused on how does Spring Boot + Angular 7 will work together. 我是Angular 7的新手。我想构建Spring Boot + Angular 7应用程序,但我对Spring Boot + Angular 7如何协同工作感到困惑。 To explain my problem, I have created a sample project where I have defined rest controllers and angular application where I have created modules and defined routes. 为了解释我的问题,我创建了一个示例项目,我已经定义了其他控制器和角度应用程序,我已经创建了模块和定义的路由。 Now when I am running the Spring boot Application from inside my IDE, then I am not able to understand the behavior of the application. 现在,当我从IDE内部运行Spring启动应用程序时,我无法理解应用程序的行为。 Some questions arising are: 出现的一些问题是:

1) when I start the application and hit http://localhost:8080 in browser, where would the call go , to Spring Boot Application server or angular server. 1)当我启动应用程序并在浏览器中点击http:// localhost:8080时,调用将转到Spring Boot Application服务器或角度服务器。

2) When I manually writing one of the route path configured in angular in the browser why the call is not going to the angular server. 2)当我在浏览器中手动编写以角度配置的路径路径之一时,为什么呼叫不会进入角度服务器。

An overview of how spring boot and angular work in combination would help in understanding and start writing code in the application. 概述弹簧引导和角度组合的组合将有助于理解并开始在应用程序中编写代码。

As per my understanding of Angular 7 as of now, the default index.html is loaded where we specify our app-component to load and further in the app-component we specify our other components to load . 根据我对Angular 7的理解,截至目前,我们指定了要加载的app-component,并且在app-component中我们指定了要加载的其他组件。 In case of router configurations we simply specify <router-outlet></router-outlet> in the app.component.html. 如果是路由器配置,我们只需在app.component.html中指定<router-outlet></router-outlet>即可。 But how does this understanding fit in when angular 7 is running in combination with Spring Boot. 但是当角度7与Spring Boot一起运行时,这种理解是如何适应的。

There is no Angular server. 没有Angular服务器。 It's a JavaScript framework, that runs entirely in the browser. 它是一个JavaScript框架,完全在浏览器中运行。

If you send a request to your Spring Boot server, then the Spring Boot server answers, according to the rules of Spring Boot alone. 如果您向Spring Boot服务器发送请求,则Spring Boot服务器会根据Spring Boot的规则应答。 The Angular application is just a bunch of static JS, CSS files, and an index.html static file, that are served by your Spring Boot server. Angular应用程序只是一堆静态JS,CSS文件和一个index.html静态文件,由Spring Boot服务器提供。

If you navigate using the Angular router through your Angular application routes, then it all happens inside the browser (ie Angular basically changes the URL in the browser location bar). 如果您通过Angular应用程序路由使用Angular路由器进行导航,那么这一切都发生在浏览器中(即Angular基本上更改了浏览器位置栏中的URL)。 If you refresh, however, you will indeed send a request to the Spring Boot server, which will have to serve the index.html page again, to reload and restart the Angular single page app (as described in the guide ) 但是,如果刷新,您确实会向Spring Boot服务器发送请求,该服务器必须再次提供index.html页面,以重新加载并重新启动Angular单页面应用程序(如指南所述

If You have not change any configurations such as ports for both angular and spring boot. 如果您没有更改任何配置,例如角度和弹簧启动的端口。 then angular runs on http://localhost:4200 and spring boot runs on http://localhost:8080 . 然后angular在http://localhost:4200运行,spring boot在http://localhost:8080
If you want to hit end points of back-end from front-end then you need to proxy your requests to http://localhost:8080 . 如果要从前端命中后端的端点,则需要将请求代理到http://localhost:8080
how to proxy your requests check here 如何代理您的请求请在此处查看
1) when I start the application and hit http://localhost:8080 in browser, where would the call go , to Spring Boot Application server or angular server. 1)当我启动应用程序并在浏览器中点击http:// localhost:8080时,调用将转到Spring Boot Application服务器或角度服务器。 - will call back-end or spring boot. - 将调用后端或弹簧启动。

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

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