title: Which spring view resolver plays nice with angularjs?
body: <p>I'm writing a webapp using angularjs and spring mvc as a REST service provider and as a partial view provider(I'm also using angular-ui-router so that I can have multiple nested partials). I currently don't have any use for template languages since I plan on doing everything in angular, however every single view resolver I've tried has some type of template language which clashes with angular and either crashes the application and/or fills my logs with errors.</p>
  
  <p>First I tried using InternalResourceViewResolver but no luck as it seems that it only expects .jsp files and won't show anything else.</p>
  
  <p>Then I tried using Thymeleaf. Thymeleaf follows the XML standard which forced me to rewrite most of my html to follow the xml requirements, and after I'd done that it died upon encountering a <code>&amp;&amp;</code> inside an ng-show directive. So no luck with that either.</p>
  
  <p>Then I tried Velocity. I've had most luck with velocity so far. It serves up html files nicely, doesn't stop upon encountering parse errors and allows me to serve up partial views the same way InternalResourceViewResolver does. However upon encountering angular variables prefixed by <code>$</code> Velocity tries to parse them as VTL variables and fills my logs with messages like</p>
  
  <p><code>velocity - Null reference [template 'clients/createOrEdit.html', line 1, column 65] : $invalid cannot be resolved.</code></p>
  
  <p>Everything keeps working as it should but I'm not the one to just leave errors be, and I've found no way of disabling VTL.</p>
  
  <p>That's my current experience with view resolvers.</p>
  
  <p>I've also had an idea to treat .html files as static resources(which they kinda are before angular does it's magic) using <code>mvc:resources</code> but without any view resolver my application failed to start even if I set the main layout.html to be the welcome-file in web.xml</p>
  
  <p>My question is. What should I use as a view resolver so that it plays nice with angularjs, and if I should even use view resolvers?</p>
  
  <p><strong>EDIT:</strong> I'm trying to use the <code>ContentNegotiatingViewResolver</code> and I get:</p>
  
  <pre><code>DEBUG ContentNegotiatingViewResolver - Requested media types are [text/html] based on Accept header types and producible media types [*/*])
  DEBUG ContentNegotiatingViewResolver - No acceptable view found; returning null
  DEBUG DispatcherServlet - Could not complete request
  javax.servlet.ServletException: Could not resolve view with name 'layout.html' in servlet with name 'springDispatcherServlet'
  </code></pre>
  
  <p>webapp-config.xml (contextconfig in dispatcher servlet)</p>
  
  <pre><code>    &lt;mvc:annotation-driven /&gt;
  
      &lt;!-- Resources --&gt;
      &lt;mvc:resources location="/libs/" mapping="/libs/**" /&gt;
      &lt;mvc:resources location="/css/" mapping="/css/**" /&gt;
      &lt;mvc:resources location="/js/" mapping="/js/**" /&gt;
      &lt;!-- Angular application data --&gt;
      &lt;mvc:resources location="/WEB-INF/appjs/" mapping="/appjs/**" /&gt;
      &lt;!-- View locations --&gt;
      &lt;mvc:resources location="/WEB-INF/html/" mapping="/**"/&gt;
  
      &lt;!-- Controllers --&gt;
      &lt;context:component-scan base-package="com.mrplow.controller" /&gt;
  
      &lt;!-- Views --&gt;
      &lt;util:map id="contentMediaTypes"&gt;
          &lt;entry key="json" value="application/json" /&gt;
          &lt;entry key="html" value="text/html" /&gt;
      &lt;/util:map&gt;
  
  &lt;!--    &lt;util:list id="defaultViews"&gt; --&gt;
  &lt;!--        &lt;bean class="org.springframework.web.servlet.view.json.MappingJackson2JsonView" /&gt;       --&gt;
  &lt;!--    &lt;/util:list&gt; --&gt;
  
      &lt;bean id="viewResolver" class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"
      p:order="1"
      p:ignoreAcceptHeader="false"
      p:defaultContentType="text/html"
      p:mediaTypes-ref="contentMediaTypes" /&gt; 
  </code></pre>
  
  <p>LayoutController.java</p>
  
  <pre><code>@Controller
  @RequestMapping("/")
  public class LayoutController {
  
      @RequestMapping
      public String getIndexPage() {
          return "layout";
      }
  }
  </code></pre>