0

I have a webapp based on Spring 3.0.6 which works fine on Tomcat 7.0.

The web.xml defines the dispatcher as following:

<servlet>
  <servlet-name>dispatcher</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  <load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
  <servlet-name>dispatcher</servlet-name>
  <url-pattern>/</url-pattern>
</servlet-mapping>

The dispatcher defines the view resolver in the usual way:

<bean id="tilesViewResolver"
    class="org.springframework.web.servlet.view.UrlBasedViewResolver">
  <property name="viewClass"
      value="org.springframework.web.servlet.view.tiles2.TilesView" />
</bean>

<bean id="tilesConfigurer"
    class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
  <property name="definitions">
    <list>
      <value>/WEB-INF/tiles-def.xml</value>
    </list>
  </property>
</bean>

I have a controller annotated with @RequestMapping("/home") and a "home" view defined in tiles-def.xml. When I point my browser to the /myapp/home.html, the Tiles page is opened.

If I add <mvc:resources mapping="/resources/**" location="/resources/" /> or <mvc:view-controller path="/" view-name="home.html"/> to my dispatcher xml file, pointing the browser to /myapp/home.html results in a 404. The log says:

21:34:22,128  WARN PageNotFound:947 – No mapping found for HTTP request with URI [/myapp/home.html] in DispatcherServlet with name 'dispatcher'

What am I doing wrong?

Thanks a lot

Ciaccia
  • 382
  • 3
  • 14
  • You can set a breakpoint in DispatcherServlet.doDispatch and see what's going on. :) – Boris Treukhov Sep 11 '11 at 08:27
  • 1
    Hi Boris, I tried to debug but the internal working of the dispatcher servlet was pretty complex to understand. The problem was that the method in my MVC Controller was `void` and did not return any string, so the framework tried to resolve the view automatically using the path. I changed this returning explicitly the Tiles2 view name, and everything worked again. I learned the lesson, never let Spring guess anything... ;-) – Ciaccia Sep 19 '11 at 10:36
  • Ok. Please post your results as an answer and close the question )). – Boris Treukhov Sep 19 '11 at 17:04

1 Answers1

0

The problem in my application was due to the automatic view name resolution. My annotated method in my @Controller returned void, and the framework tried to guess the tiles view name using the request path.

I modified my annotated method as following, returning a String:

@RequestMapping(value="/page", method = RequestMethod.GET)
public String showForm(HttpServletRequest request, Model model) {
    // TO BUSINESS LOGIC

    // return tiles view name as configured in 'tiles-def.xml'
    return "my_tiles_view_name";
}

With this change, everything works fine.

Ciaccia
  • 382
  • 3
  • 14