Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I recently came across AngularJS. I am a java web developer. I want to use AngularJS along with Spring-MVC framework. But I need some basic foundation (tutorial) to start with.

I know about the basic stuff of AngularJS, but how to integrate it with Spring-MVC. As most of the time spring it self return partial jsp(s), and we add them using jsp-include, while AngularJS expects JSON data most of the time.

share|improve this question

closed as off-topic by skrrgwasme, Dan Beaulieu, ryanyuyu, nha, Jacob Mar 11 at 23:54

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it." – ryanyuyu, nha, Jacob
If this question can be reworded to fit the rules in the help center, please edit the question.

up vote 48 down vote accepted

Two cases:

  1. Your architecture is full client-side: In this case the integration is very natural. Spring MVC exposes your service as a REST (JSON/XML) and your client application with AngularJS consumes your JSON. Here the .war application (Spring MVC) must be deployed in a servlet container (e.g. Tomcat) and your client application can be deployed in the same server or in a HTTP server like Nginx or Apache.

  2. You want to keep page generation in the server-side and only use AngularJS for some DOM manipulation so your code must be deployed in the same .war (inside the WEB-INF/ folder).

Mixing the two approaches in not always a good idea. You can try Thymeleaf to stay in server-side page generation and at the same time have templating, testability and clean View code.

share|improve this answer
    
Thank you for the insight. As far as war (Spring-MVC) is concerned I have the application ready with REST service. It was just should directly have .html pages in my views or I should use as usual .jsp page with AngularJS because finally when they are rendered on client side they are html. – Priyank Thakkar Sep 2 '13 at 12:38
3  
If your application is full REST , you don't need to go with JSP . It will introduce complexity , use only HTML files . Pay attention about you Model of Security and authorization , Backend generation(JSP) and the use of spring security make things very easy with the JSP tag lib of spring security , you will need to handle this manually in the client side . This nice directive can help you github.com/witoldsz/angular-http-auth – Nabil Sep 10 '13 at 10:01
    
Thanks Nabil. I will try that. At present I have kept my shell as jsp page. All the partials are .html, but I will definitely look into the github link you gave. With HTML I was worried about security – Priyank Thakkar Sep 10 '13 at 10:30
    
You are right to be worried about security , not about the reliability but about the effort of implementing functionality that spring-security do for you in one line of code . Good Luck – Nabil Sep 10 '13 at 10:56
    
Yes. I agree :) – Priyank Thakkar Sep 10 '13 at 11:59

Just set angular.js files as static files . There should be nothing private there anyway.

Use Spring MVC as a REST Service provider instead of JSP/Velocity/Any other Template view resolver.

You have sample projects on the folowing sites:

share|improve this answer
    
Thank you mite. I will look into these projects and discussions. – Priyank Thakkar Sep 1 '13 at 11:36
    
first link is very good,Thanks – userRaj May 11 at 7:24

If you like to learn by example you can try to generate some code with jhipster: https://jhipster.github.io/

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.