title: Spring 3 MVC and Tiles 2 - can't display static resources when controller @RequestMapping has URI template
body: <p>I am using Tiles 2, Spring 3 MVC, Tomcat ver.7 and Eclipse (Springsource Tool Suite). I hope somebody can help. </p>
  
  <p>The css and pictures are not rendered by the tile view that is returned by the controller handler method "displayPropertyPage" whose @RequestMapping has a URI template ( @RequestMapping(value = <strong>"/getproperty/{propertyID}"</strong>, method = RequestMethod.GET) ).</p>
  
  <p>I am using the <strong>mvc:resources</strong> and <strong>mvc:default-servlet-handler</strong> tags so the default servlet serves requests for static resources. I also checked the html script generated by this tile view and it does have the css entry.</p>
  
  <p>The other views returned by controller handler methods with a simple path such as ( @RequestMapping(value = "/propertylistings", method = RequestMethod.GET) ) display all static resources including 
  css, pictures and jquery just fine.</p>
  
  <p>I noticed that the 'properties info' of the blank picture on the browser has a URL of <em>http://localhost:8080/realtyguide/<strong>getproperty</strong>/resources/images-homes/pic1.jpg</em> when it should be
  just <em>http://localhost:8080/realtyguide/resources/images-homes/pic1.jpg</em>. The URL is picking up the path "/getproperty" from the handler's RequestMapping annotation.</p>
  
  <p>The pictures are under the folder 'images-homes'. </p>
  
  <p>My directory structure is:</p>
  
  <ul>
  <li>src
  <ul>
  <li>main
  <ul>
  <li>webapp
  <ul>
  <li>resources
  <ul>
  <li>images-homes</li>
  <li>css</li>
  </ul></li>
  <li>WEB-INF</li>
  </ul></li>
  </ul></li>
  </ul></li>
  </ul>
  
  <p>Here is my controller. The view returned is a tile definition.</p>
  
  <pre><code>@Controller
  public class PropertyPageController {
  
      private MasterTableService masterTableService;
  
      @Autowired
      public PropertyPageController(MasterTableService masterTableService) {
          this.masterTableService = masterTableService;
      }
  
      @RequestMapping(value = "/getproperty/{propertyID}", method = RequestMethod.GET)
      public String displayPropertyPage(@PathVariable("propertyID") String propertyID, Model model) {
  
          model.addAttribute("mastertable", masterTableService.findByID(propertyID));
  
          return "propertyinfo.tiledef";
      }
  
  }
  </code></pre>
  
  <p>Here is my Spring application servlet configuration:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:aop="http://www.springframework.org/schema/aop"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:mvc="http://www.springframework.org/schema/mvc"
      xmlns:jee="http://www.springframework.org/schema/jee"
      xmlns:lang="http://www.springframework.org/schema/lang"
      xmlns:p="http://www.springframework.org/schema/p"
      xmlns:tx="http://www.springframework.org/schema/tx"
      xmlns:util="http://www.springframework.org/schema/util"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
          http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-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/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
          http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.0.xsd
          http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
          http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd"&gt;
  
      &lt;context:annotation-config /&gt;
  
      &lt;!-- Scans within the base package of the application for @Components to configure as beans --&gt;
      &lt;context:component-scan base-package="com.springproject.realtyguide" /&gt;
  
      &lt;!-- Enables the Spring MVC @Controller programming model --&gt;    
      &lt;mvc:annotation-driven /&gt;
  
      &lt;!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources --&gt;
      &lt;mvc:resources mapping="/resources/**" location="/resources/"/&gt;   
  
      &lt;!-- Allows for mapping the DispatcherServlet to "/" by forwarding static resource requests to the container's default Servlet --&gt;
      &lt;mvc:default-servlet-handler/&gt;      
  
  
      &lt;!-- Bean to provide Internationalization  --&gt;
      &lt;bean id="messageSource"
          class="org.springframework.context.support.ReloadableResourceBundleMessageSource"&gt;
          &lt;property name="basename" value="WEB-INF/i18n/messages" /&gt;
          &lt;property name="defaultEncoding" value="UTF-8" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="propertyConfigurer"
          class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
          p:location="classpath:META-INF/spring/database.properties" /&gt;
  
      &lt;bean id="dataSource"
          class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"
          p:driverClassName="${jdbc.driverClassName}"
          p:url="${jdbc.databaseurl}" p:username="${jdbc.username}"
          p:password="${jdbc.password}" /&gt;
  
      &lt;bean id="sessionFactory"
          class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"&gt;
          &lt;property name="dataSource" ref="dataSource" /&gt;
          &lt;property name="configLocation"&gt;
              &lt;value&gt;classpath:META-INF/hibernate.cfg.xml&lt;/value&gt;
          &lt;/property&gt;
          &lt;property name="configurationClass"&gt;
              &lt;value&gt;org.hibernate.cfg.AnnotationConfiguration&lt;/value&gt;
          &lt;/property&gt;
          &lt;property name="hibernateProperties"&gt;
              &lt;props&gt;
                  &lt;prop key="hibernate.dialect"&gt;${jdbc.dialect}&lt;/prop&gt;
                  &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;
              &lt;/props&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;!-- Enable the configuration of transactional behavior based on annotations --&gt;
      &lt;tx:annotation-driven /&gt;
  
      &lt;bean id="transactionManager"
          class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt;
          &lt;property name="sessionFactory" ref="sessionFactory" /&gt;
      &lt;/bean&gt;
  
      &lt;!-- __________ BEAN ENTRIES FOR TILES 2 --&gt;
  
      &lt;bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer"&gt;
          &lt;property name="definitions"&gt;
              &lt;list&gt;
                  &lt;value&gt;/WEB-INF/layouts/tiles.xml&lt;/value&gt;
              &lt;/list&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean id="tilesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver" &gt;
          &lt;property name="order" value="0"/&gt; 
          &lt;property name="viewClass"&gt; 
              &lt;value&gt;org.springframework.web.servlet.view.tiles2.TilesView &lt;/value&gt;
          &lt;/property&gt;
          &lt;property name="requestContextAttribute" value="requestContext"/&gt;
          &lt;property name="viewNames" value="*.tiledef"/&gt;
      &lt;/bean&gt;
  
      &lt;bean id="jstlViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt; 
          &lt;property name="order" value="1"/&gt; 
          &lt;property name="viewClass"&gt;
              &lt;value&gt;org.springframework.web.servlet.view.JstlView&lt;/value&gt;
          &lt;/property&gt;
          &lt;property name="prefix" value="/WEB-INF/views/"/&gt; 
          &lt;property name="suffix" value=".jsp"/&gt; 
      &lt;/bean&gt; 
  
      &lt;!-- __________ END OF BEAN ENTRIES FOR TILES 2 --&gt;
  
      &lt;!-- Resolves localized &lt;theme_name&gt;.properties files in the classpath to allow for theme support --&gt;
      &lt;bean id="themeSource" class="org.springframework.ui.context.support.ResourceBundleThemeSource"&gt;
          &lt;property name="basenamePrefix" value="theme-" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="themeResolver" class="org.springframework.web.servlet.theme.CookieThemeResolver"&gt;  
          &lt;property name="defaultThemeName" value="standard" /&gt;
      &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>Here is my 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://java.sun.com/xml/ns/javaee" 
      xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"&gt;
  
    &lt;display-name&gt;Realty Guide&lt;/display-name&gt;
  
        &lt;!-- The definition of the Root Spring Container shared by all Servlets and Filters --&gt;
        &lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;/WEB-INF/spring/root-context.xml&lt;/param-value&gt;
        &lt;/context-param&gt;
  
        &lt;!-- Creates the Spring Container shared by all Servlets and Filters --&gt;
        &lt;listener&gt;
          &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
        &lt;/listener&gt;
  
        &lt;!-- Handles Spring requests --&gt;
        &lt;servlet&gt;
          &lt;servlet-name&gt;appServlet&lt;/servlet-name&gt;
          &lt;servlet-class&gt;
                  org.springframework.web.servlet.DispatcherServlet
          &lt;/servlet-class&gt;
          &lt;init-param&gt;
            &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
            &lt;param-value&gt;/WEB-INF/spring/appServlet/servlet-context.xml&lt;/param-value&gt;
          &lt;/init-param&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
        &lt;/servlet&gt;
        &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;appServlet&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/&lt;/url-pattern&gt;
        &lt;/servlet-mapping&gt;
  
  &lt;/web-app&gt;
  </code></pre>
  
  <p>I have been googling this for several days and can't find a solution.</p>
  
  <p>Thanks for any help you can give.</p>