This post is all about Spring MVC 3 and Google App Engine and their interaction.

The starting point for this project was the Google App Engine’s documentation, the Google Eclipse plugin, and some tutorials found on various sites.

After reading all about the App Engine and Spring, the first thing to do was to create a project in our favorite editor, Eclipse. This generated some necessary files, and gave us a good starting point. As we want to use Spring to perform all its magic, we’ve created a web.xml like this:

<servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>


This configuration would redirect all incoming requests to our Spring Dispatcher Servlet that will handle everything from there on. At leaset that’s what we’ve thought. After firing up the local App Engine development server, an error appeared for every request issued from the browser (lets say http://localhost:8888/index). We have set up mapping for that particular url in our Spring controller, but we still got the same error:

Jul 21, 2010 8:02:33 AM org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/WEB-INF/views/index.jsp] in DispatcherServlet with name 'dispatcher'

After some googling around, we have realized that there is no need for the wildcard in the url-pattern, but if we simply put “/” there, everything will work nicely.

My curiosity didn’t let me rest on this, so I have investigated a bit more. I wanted for every not specified url to fall back on the index page. Lets try adding the wildcard back to the web.xml, and also to include it in the Spring controller:

@RequestMapping("/*")
public String home (Model model) {
	return index(model);
}

And again an error:

Jul 21, 2010 8:04:32 AM org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver handleNoSuchRequestHandlingMethod
WARNING: No matching handler method found for servlet request: path '/WEB-INF/views/index.jsp', method 'GET', parameters map[[empty]]

Okay, expectedly this didn’t go well, so the third combination was the winning one: no wildcard in web.xml, and with wildcard in the Spring controller. And here are the two final codes:

Web.xml

<servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

Spring controller

@RequestMapping("/*")
public String home (Model model) {
	return index(model);
}

This have solved the issue that we were having with the App Engine not wanting to forward to the Spring controller.

Posted By Vilmos Somogyi

Frond end developer and QA consultant. In this blog I'm sharing my QA experience gained over the years of working on various QA projects.

Leave a Reply




XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>