简体   繁体   中英

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. 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. 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.

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.

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 . In case of router configurations we simply specify <router-outlet></router-outlet> in the app.component.html. But how does this understanding fit in when angular 7 is running in combination with Spring Boot.

There is no Angular server. It's a JavaScript framework, that runs entirely in the browser.

If you send a request to your Spring Boot server, then the Spring Boot server answers, according to the rules of Spring Boot alone. 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.

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). 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 )

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 .
If you want to hit end points of back-end from front-end then you need to proxy your requests to 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. - will call back-end or spring boot.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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