title: How avoid calling setApplicationContext on a SpringResourceTemplateResolver?
body: <p>I'm currently setting up a Spring MVC project with Thymeleaf, following the tutorial at: <a href="http://www.thymeleaf.org/doc/tutorials/3.0/thymeleafspring.html#spring-mvc-configuration" rel="nofollow noreferrer">http://www.thymeleaf.org/doc/tutorials/3.0/thymeleafspring.html#spring-mvc-configuration</a></p>
  
  <p>Trying to KISS the code, I first replaced <code>implements ApplicationContextAware</code> and the setter method with <code>@Inject private ApplicationContext applicationContext</code>.
  But I don't understand why I have to call <code>setApplicationContext()</code> on the <code>SpringResourceTemplateResolver</code> while it inherits the Spring interface <code>ApplicationContextAware</code>.</p>
  
  <p>How to avoid this?</p>
  
  <p>Edit:
  If I remove the <code>templateResolver.setApplicationContext(applicationContext);</code> line, I get this exception when accessing the root:</p>
  
  <pre><code>java.lang.IllegalArgumentException: Application Context cannot be null
      org.thymeleaf.util.Validate.notNull(Validate.java:37)
      org.thymeleaf.spring4.templateresource.SpringResourceTemplateResource.&lt;init&gt;(SpringResourceTemplateResource.java:64)
      org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver.computeTemplateResource(SpringResourceTemplateResolver.java:69)
      org.thymeleaf.templateresolver.AbstractConfigurableTemplateResolver.computeTemplateResource(AbstractConfigurableTemplateResolver.java:1221)
      org.thymeleaf.templateresolver.AbstractTemplateResolver.resolveTemplate(AbstractTemplateResolver.java:356)
      org.thymeleaf.engine.TemplateManager.resolveTemplate(TemplateManager.java:840)
      org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:608)
      org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1087)
      org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1061)
      org.thymeleaf.spring4.view.ThymeleafView.renderFragment(ThymeleafView.java:335)
      org.thymeleaf.spring4.view.ThymeleafView.render(ThymeleafView.java:189)
      org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1257)
      org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1037)
      org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:980)
      org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
      org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
      org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
      org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
      org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  </code></pre>
  
  <p>Note: I use the latest versions: Spring 4.3.3.RELEASE and Thymeleaf 3.0.2.RELEASE (of course I imported <code>thymeleaf-spring4</code>).</p>