title: Spring Framework 4 & Apache Tiles 3 - no such definition error
body: <p>I have had a bit of a look around and can't seem to find a post with the scenario that i've come across.</p>
  
  <p>I have written a small web app that utilises Spring MVC 4 and apache tiles 3. I am using apache tiles as I wanted to create a master page template in order to keep the application look and feel constant. I have been developing this in eclipse and running it on and apache 8 server through the IDE. This has all been running absolutely fine through eclipse and the templating was working well.</p>
  
  <p>When I have exported the project as a .war file and run it up on the same apache 8 server outside of the IDE I am receiving the following stack trace when trying to view pages that use the tiles templating:</p>
  
  <pre><code>    2: &lt;%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %&gt;
  3: &lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
  4:     pageEncoding="ISO-8859-1"%&gt;
  5: &lt;tiles:insertDefinition name="defaultTemplate"&gt;
  6:  &lt;tiles:putAttribute name="body"&gt;
  7: &lt;div class="body"&gt; 
  8:  Hi &lt;c:out value="${uacc_fname}"&gt;&lt;/c:out&gt; &lt;c:out value="${uacc_sname}"&gt;&lt;/c:out&gt; welcome to the home page!!
  
  
  Stacktrace:
      org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:470)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:403)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:347)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
      org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
      org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:209)
      org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:267)
      org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1221)
      org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1005)
      org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:952)
      org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
      org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
      org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
      org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
      org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
      org.SouthC.Messwich.WebApp.FilterAuthCheck.doFilter(FilterAuthCheck.java:80)
  root cause
  
  org.apache.tiles.definition.NoSuchDefinitionException: Unable to find the definition 'defaultTemplate'
      org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:218)
      org.apache.tiles.template.InsertDefinitionModel.renderDefinition(InsertDefinitionModel.java:132)
      org.apache.tiles.template.InsertDefinitionModel.execute(InsertDefinitionModel.java:99)
      org.apache.tiles.jsp.taglib.InsertDefinitionTag.doTag(InsertDefinitionTag.java:254)
      org.apache.jsp.webapp.home_jsp._jspx_meth_tiles_005finsertDefinition_005f0(home_jsp.java:105)
      org.apache.jsp.webapp.home_jsp._jspService(home_jsp.java:77)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:403)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:347)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
      org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
      org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:209)
      org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:267)
      org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1221)
      org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1005)
      org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:952)
      org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
      org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
      org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
      org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
      org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
      org.SouthC.Messwich.WebApp.FilterAuthCheck.doFilter(FilterAuthCheck.java:80)
  
      org.apache.jasper.JasperException: An exception occurred processing JSP page /webapp/home.jsp        at line 5
  </code></pre>
  
  <p>I have checked that the server can definately read the tiles.xml definition file as when I remove it from the location that it is specified in, a different error comes up on start up. Below are my configuration files:</p>
  
  <p>servlet.xml</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:mvc="http://www.springframework.org/schema/mvc"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="
          http://www.springframework.org/schema/beans     
          http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
          http://www.springframework.org/schema/mvc 
          http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
          http://www.springframework.org/schema/context 
          http://www.springframework.org/schema/context/spring-context-3.0.xsd"&gt;
  
      &lt;context:component-scan base-package="org.test.WebApp"/&gt;
  
      &lt;mvc:annotation-driven/&gt;
  
     &lt;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
        &lt;property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/&gt;
        &lt;property name="prefix" value="" /&gt;
        &lt;property name="suffix" value=".jsp" /&gt;
        &lt;property name="order" value="1" /&gt;
     &lt;/bean&gt;
      &lt;bean id="tilesConfigurer"
          class="org.springframework.web.servlet.view.tiles3.TilesConfigurer"&gt;
          &lt;property name="definitions"&gt;
              &lt;list&gt;
                  &lt;value&gt;/tiles/tiles.xml&lt;/value&gt;
              &lt;/list&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;mvc:resources mapping="/resources/**" location="/resources/" /&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>web.xml</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"&gt;
    &lt;display-name&gt;Messwich&lt;/display-name&gt; 
    &lt;servlet&gt;
      &lt;servlet-name&gt;testWebApp&lt;/servlet-name&gt;
      &lt;servlet-class&gt; org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;testhWebApp&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>tiles.xml</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="ISO-8859-1" ?&gt;
  &lt;!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN" "http://tiles.apache.org/dtds/tiles-config_3_0.dtd"&gt;
  
          &lt;tiles-definitions&gt;
  
      &lt;definition id="defaultTemplate" name="defaultTemplate" template="/template/defaultTemplate.jsp"&gt;
          &lt;put-attribute id="header" name="header" value="/template/header.jsp" /&gt;
          &lt;put-attribute id="footer" name="footer" value="/template/footer.jsp" /&gt;
      &lt;/definition&gt;
  
  &lt;/tiles-definitions&gt;
  </code></pre>
  
  <p>Any help with this would be much appriciated, I'm just not sure why it works through the IDE but not when it is exported.</p>
  
  <p>Thanks in advance.</p>
  
  <p>Phil</p>