0

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?

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks a ton for clearing that confusion up, I will browse around a bit to figure out how to use angular in a production environment.
Went through this youtube tutorial, its short and precise and covers the basics brilliantly.
Or you can serve the static files on a different location, for instance a separate webserver or cdn (in production).
Thanks for this gem. After reading a lot of confusing tutorial on angular2 I came across this answer and the first line made it clear. thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.