首页 > 解决方案 > Angular App out of the box on localhost?

问题描述

I want to build a new app and this time I want to try to use Angular CLI 6.

The app should just service the user on localhost. And it should be DAU safe.

Until now I always worked with SpringBoot, Spring MVC and Thymleaf+Bootstreap+JQuery.

The advantage:

I am not that sure if this is possible with a Spring MVC Application combined with Angular.

If I am right, the users needs to install besides Java also npm right? And to make the application running the user has to install all dependencies of Angular as well he has to use more commands instead of only java -jar file.jar like ng serve.

Are there any toolkit to make this more easy for the DAU or is what I plan not appropriate with Angular+Spring for an userfriendly/easy localhost app?

标签: angularspring-boot

解决方案


Angular is a front-end framework for SPA solutions. Spring MVC typically does not follow the SPA architecture, and renders its own HTML webpage on each load. That is where Thymeleaf comes in, filling the template engine role.

While you can use Angular as a simple rendering library that does not feature router capabilities, and let Spring do the routing/migrating, it is not what the framework was designed for, and you might be better off with a simpler rendering library like React.

  • If you still choose Angular-as-a-renderer approach, you'll have to basically start a different angular app on each page load. However you can still use a single ui library structure, with a single node_modules folder. The Spring-produced jar has to include the static assets provided by compiling each mini Angular app.

  • If you follow the SPA architecture, Spring has to behave like a plain API, and not produce any HTML. All communication is done via AJAX requests. You can serve the produced static files using a cdn, static file server, or include them in your Spring-produced jar file so that it is deployed and served by your Spring server. Just don't forget to add base redirect or routing to the Angular's index.html file.


推荐阅读