It is amazingly easy to get Spring running on Google App Engine. Here is how you do it.
Install the development environment
I’m assuming you installed a recent version of the JDK. Once Java is installed on your system download either Eclipse or the Spring Tool Suite (STS), which is build on top of Eclipse.
I personally decided for the Spring Tool Suite because it makes it ridiculously simple to install additional plug-ins like for example the Google Plugin and comes with support for Groovy and Grails which I both want to try out at some point. After starting up STS, you’re presented with the STS Dashboard.

Click on the “Extensions”-link and search for the “Google Plugin”. I already installed it, that’s why it’s displayed as installed on below screenshot, but when you get to that page the first time, you can click the check-box on the left and then hit the “Install” button in the lower right corner. It will take a little to install the plugin, but once that’s done you’re ready to go.

Create an App Engine Project
For the sake of simplicity I will create an App Engine project only without Google Web Toolkit. Click on the Google Plugin icon (
) and specify a project name, a package and disable the GWT check-box.

The plug-in will auto-generate some example code for you which you can deploy straight away to App Engine.
Deploying the App to App Engine
If you haven’t signed up for Google App Engine yet, now is the right time to do so: code.google.com/intl/de/appengine.
Next navigate to appengine.google.com. All you will see is a rather empty screen (at least if you just signed up for App Engine). Click on the “Create Application”-button and fill in the form.

Typically it requires some creativity to select an app ID. I usually use the name I want to use and add some random numbers. That works out well most of the time. If you plan to develop and production application, the app ID doesn’t really matter anyway because you can use a custom domain later on. Once things are set up on Google’s side, hit the “Deploy”-button in STS: ![]()
On the upcoming screen, click “App Engine Project Settings …” and specify the app ID you chose in the last step.

Type in the app ID and confirm with OK. Now type in your Gmail address and the password and hit deploy. After a couple of seconds your app will be available at “your app id”.appspot.com.
Adding Spring
Now you will add Spring to the application. Instead of using a simple servlet to return the “Hello World” string you will use a Spring MVC controller.
Adding the right JARs
- Download the latest version of Spring 3. I used Spring 3.0.4.
- Extract the zip file a copy following JARs to the /war/WEB-INF/lib directory:
- org.springframework.asm-3.0.4.RELEASE.jar
- org.springframework.beans-3.0.4.RELEASE.jar
- org.springframework.context-3.0.4.RELEASE.jar
- org.springframework.core-3.0.4.RELEASE.jar
- org.springframework.expression-3.0.4.RELEASE.jar
- org.springframework.web-3.0.4.RELEASE.jar
- org.springframework.web.servlet-3.0.4.RELEASE.jar
- Additionally you’ll have to add these JARs to your lib directory:
- Rename commons-logging-1.1.1.jar to something else, e.g. commons-logging-1.1.1-personal.jar
- Add the JARs to your Build Path.
Configuring the App
First, you tell the application to use the Spring Dispatcher Servlet and map it to the root URL. This is the web.xml after the changes:
< ?xml version="1.0" encoding="utf-8"?> <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" version="2.5"> <servlet> </servlet><servlet -name>SpringAppEngine</servlet> <servlet -class>org.springframework.web.servlet.DispatcherServlet</servlet> <load -on-startup>1</load> <servlet -mapping> </servlet><servlet -name>SpringAppEngine</servlet> <url -pattern>/</url> <welcome -file-list> </welcome><welcome -file>index.html</welcome> </web>
Now create a file named “SpringAppEngine-servlet.xml” and paste below XML:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | < ?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <context:component -scan base-package="com.projectsierra.springappengine" /> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/views/" p:suffix=".jsp" /> </beans> |
Line 8 tells Spring where to look for your controllers. Line 10 specifies that you will use JSPs as View technology.
Now, the last two things you need to do, is to create an actual controller and a JSP view. First, delete the auto-generated SpringAppEngineServlet class and instead create a HelloWorldController:
package com.projectsierra.springappengine; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @Controller public final class HelloWorldController { @RequestMapping(value = "/springappengine", method = RequestMethod.GET) public String HelloWorld() { return "MyView"; } }
Next create a folder “views” within the WEB-INF folder. Add a file named MyView.jsp. The sole content of MyView.jsp is the string “Hello World”.
That’s it. Start up the development server and hit http://localhost:8888/springappengine:

By clicking the deployment button a second time you can deploy this version of the application to App Engine. If you want to preserve the first version, change the version number in the App Engine Project Settings before you deploy. A live version of above code runs at http://2.springapptest987654321.appspot.com/springappengine.
Resources
- Download the example code here.
- Spring on GAE
- Spring MVC Documentation


I'm a Software Developer, currently working at