I'm trying to create an application using Angularjs for the UI including angular-route for modularity, then making calls to Spring MVC to in turn call DAOs to perform some basic CRUD. The trouble is getting both to work at the same time. So far, everything I do causes one or the other to 404.
I may be wrong, but I think the problem is rooted in web.xml, and specifically the url-pattern. For example, if I set up the the mapping like so:
<servlet-mapping>
<servlet-name>MyApp</servlet-name>
<url-pattern>/obviousJunk</url-pattern>
</servlet-mapping>
Then the application runs, I can preview my html pages, and see how all my <div>
s and <table>
s and <img>
s look all pretty. These pages have urls of the form http://localhost:8080/MyApp/#!/home or http://localhost:8080/MyApp/#!/categoryList
and so on, that is, all having the angular-route "#!" pattern.
With this <url-pattern>
, of course my servlet can't be invoked. However, if I change the above to:
<servlet-mapping>
<servlet-name>MyApp</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
And hit http://localhost:8080/MyApp/services/category/list, then I can successfully execute this method:
@RequestMapping(value="/services/category/list", method=RequestMethod.GET)
public @ResponseBody String listCategory() {
return "Hello, World";
// TODO: modify this method to make a DAO call and return a list of categories
}
But all of my pages with the "#!" suddenly go 404, as there is no controller method around to serve them, nor should there be.
I thought that if I prefaced all the service call urls with "/services/" (as shown above), then I might be able to modify my web.xml as so (with and without the *)
<servlet-mapping>
<servlet-name>MyApp</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
Likewise, I changed the @RequestMapping annotation to include and to remove the "/services" portion. No good- I can view my pages again, but the service calls 404. The controller method is never even called. I also noted some examples of adding ".do" to the end of service method calls, and making the above <url-pattern>*.do</url-pattern>
. This also fails- the http://localhost:8080/MyApp/services/category/list.do gives 404, and the
controller method is never called, even when adding ".do" at the end of the @RequestMapping value.
I've read a couple other questions here about excluding specific things from <url-pattern>
, i.e. anything with "#!" in it, but the answers all say this
is not possible. I also briefly tried a do nothing method with @RequestMapping(value="/#!/**")
and it was never called (I suspected it wouldn't work, but it was worth a try.)
How do I resolve this?