Sadiq Ali
Sadiq Ali

Reputation: 1352

Angular 2 Basics - Integration with Spring Boot - Can Angular 2 instance run within a server

I am new to angular 2 and js frameworks so this question is probably going to sound a bit stupid, I have a task at work where I am looking to integrate angular 2 with Spring boot application, I went through couple of tutorials online and found that you can configure the proxy setting for paths inside angular to redirect calls to spring boot application for various paths.

For reference: https://dzone.com/articles/angular-2-and-spring-boot-development-environment

The question I want to ask is that since Angular is a js framework and I thought that it could be completely integrated with any application, like plain old javascript, html and css. In a way that only a single port is required to launch the server and jsp based models can be served through it.

But with Angular2 you need a separate port of its own to do anything. Is that true?

If it is then why it is like that?

If not then can you please direct me to a guide which describes how to integrate it in a way that it would be served through the server?

Upvotes: 0

Views: 739

Answers (1)

JB Nizet
JB Nizet

Reputation: 691943

But with Angular2 you need a separate port of its own to do anything. Is that true?

No, not at all. An Angular application, once built, is just a set of satic files that can be served by any web server, including the one running your spring boot app. Those file aren't "run" on the server. They're just downloaded by the browser.

During development, though, it's much more productive to have a separate web server like the one that Angular CLI starts up, and which watches your source files, rebuilds your application on the fly, and serves it immediately. Since this server can also serve as a proxy to your spring server, you can just pretend your spring server hosts the angular files.

An alternative is to use your angular build tool to build the app to some directory, and configure spring to serve static files from that directory.

In production, you'll simply build the production-ready angular app, integrate the generated files inside the spring boot jar file (inside the static folder, typically), and run the spring boot application as usual.

Upvotes: 2

Related Questions