Reputation: 1358
I am trying to make a web based application using Spring MVC (5th version) & Angular 5... My idea is, Spring MVC will provide restful web-services & Angular 5 will call those web-services & manages User Interface at client side..
My question is, whether I require 2 separate web applications (one for UI & one for web-services) to be run on the server ? if yes- what will be the web-server for angular 5 application ? if no - how do we integrate angular 5 with spring MVC?.. could any one provide me the working example- how to be implement spring MVC with angular 5? Is it good practice to run both the application on single web-server? What do you suggest?
Any Help would be highly appreciated... Thanks a lot in advance..
Upvotes: 2
Views: 6617
Reputation: 91
Intergrate Spring4MVC with Angular 2 on a single server. Please refer this link. It will work Angular 5 as well
Upvotes: 0
Reputation: 1530
1) you compulsory don't need 2 web application to be run on server.
2) you can build the angular project and then copy all the files from dist
directory of angular project to WebContent
directory of spring project.
3)
Follow below steps to run SPRING MVC with Angular5 on a single server.
1.Create normal Dynamic web project.
2.Add all dependancy required for spring or user maven pom.xml
3.Open CMD, navigate to angular2 application. Hit command
'npm install'
and then
'ng build'
or use 'ng build --prod' for production build.
this command will create a “dist” folder, copy all files including all folders.
4. Paste those files and folders into 'WebContent' directory.
5. Last thing, you need to change basehref=”./” in index.html.
Now you are ready to run server or you can deploy war file and serve it with tomcat or other servers.
i have found git repo containing full working example of Spring MVC with angular 2:https://github.com/rakshitshah94/Angular2-SpringBoot-Example
4) NO it can't be said good practice to include angular build files in Spring MVC project. because every time you make changes to angular, you have to rebuild your Spring war file and deploy it again to webserver.
Upvotes: 2