I am making a similar implementation starting from this example https://github.com/xvitcoder/spring-mvc-angularjs. The main difference with the sample
a) put all the AngularJS HTML files under webapp/WEB-INF/views
b) have a Spring ViewResolver mapped on /views. We are using Velocity but you can you use freechart or whatever view technology.
<bean id="viewResolver" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
<property name="resourceLoaderPath" value="/WEB-INF/views/">
</bean><!-- see xvitcoder sample for the complete web.xml-->
c) have a Controller that respond to your HTML partial requests. The magic is that the client side URL doesn't need to match the physical folder structure. This is something lacking when you have a static html project.
@RequestMapping("dummypath/{folder}/{remainder}")
public String getSomePartial(@PathVariable("folder") String folder,
@PathVariable("remainder") String path) {
return folder + "/" + path;
}
dummpypath allows to isolate the requests for AngularJS partials (ngInclude, ngView) from other requests like servlet or REST service. The HTML files are still actually under /views/folder/path. You can do more complex stuff like computing a different view name.
<div ng-include="dummypath/summary/table.html"></div>
will load the views/summary/table.html file. Your ViewResolver will preprocess this file beforehand, allowing some server side fixes.
d) Example of passing parameters to angularjs from Spring MVC.
Define the query in your Spring Controller and return a html file
@RequestMapping
public String getPage(@RequestParam(value="someparam", defaultValue="0") string myparam,
ModelMap model){
model.addAttribute("someparam", myparam)
return "index"; //index.html
}
In the AngularJs controller inject $location to retrieve the parameter.
$scope.someparam = ($location.search()).someparam
Once the index is loaded, we are in Angular ecosystem! I am using this method to refresh the webpage while retaining the context. Based on the query parameter, you can load some JSON stuff or have ngSwitch put on the right partial.
e) PROS and CONS
PROS: simply you can't always build a complete solution with static files + REST
CONS: testing and building the project requires extra steps. You need to bundle stuff in a WAR, testing them outside and inside.