<?xml version="1.0" encoding="UTF-8"?>


<rss version="2.0">
	<channel>
		<title><![CDATA[Blog]]></title>
		<description>

</description>
		
<link>
http://www.ardentlord.com/apps/blog/
</link>

		<generator>Webs.com</generator>

		    
			<item>
				<title>
Spring 3.0 on Google App Engine
</title>
				
<link>
http://www.ardentlord.com/apps/blog/show/829881
</link>

				<description>
&lt;p&gt;-- Note: If you just want the nitty gritty without my blabbing, ignore the first paragraph --&lt;/p&gt;

&lt;p&gt;So last week I got the inspiration to try out Google App Engine after reading about the new &lt;a href="http://googleappengine.blogspot.com/2009/04/seriously-this-time-new-language-on-app.html"&gt;Java support&lt;/a&gt;. I searched around to find some resources on getting Spring running on App Engine, but the resources were surprisingly scarce. Google points you to their &lt;a href="http://code.google.com/p/googleappengine/source/browse/#svn/trunk/java/demos/autoshoppe"&gt;"autoshoppe" example&lt;/a&gt;, which is a little incomplete in terms of setup and what libraries you need. Ironically, &lt;a href="http://blog.springsource.com/2009/04/07/write-your-google-app-engine-applications-in-groovy/"&gt;Spring Source's post about App Engine&lt;/a&gt; was talking about using Groovy, not Spring. Finally I found a &lt;a href="http://sikeh.javaeye.com/blog/364043"&gt;blog entry by Sikeh&lt;/a&gt;. So I got a nice Hello World up and running on Spring 2, thanks to Sikeh, but I wasn't satisfied yet. I wanted Spring 3. Spring 2 is so... 2008. So I started bringing in some Spring 3 (M2) jars, played around a little more, did some Googling, and finally got Spring 3 up and running.&lt;/p&gt;&lt;p&gt;Here's how you'll need to setup the directory structure:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;Setup a Google App Engine project (I used the &lt;a href="http://code.google.com/appengine/docs/java/tools/eclipse.html"&gt;Eclipse plugin&lt;/a&gt;)&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.springsource.com/download/community"&gt;Download Spring&lt;/a&gt; 3.0.0.M2 (or the latest version)&lt;/li&gt;&lt;li&gt;Copy the following jar files from Spring into the /war/WEB-INF/lib directory:

&lt;br/&gt;org.springframework.beans-3.0.0.M2.jar
&lt;br/&gt;org.springframework.context-3.0.0.M2.jar
&lt;br/&gt;org.springframework.core-3.0.0.M2.jar
&lt;br/&gt;org.springframework.expression-3.0.0.M2.jar
&lt;br/&gt;org.springframework.web-3.0.0.M2.jar
&lt;br/&gt;org.springframework.web.servlet-3.0.0.M2.jar
&lt;/li&gt;&lt;li&gt;Spring also depends on the following jars, which you can search for around the internet, or download from my Spring Example git repository:
&lt;br/&gt;antlr-3.0.1.jar
&lt;br/&gt;asm-2.1.jar
&lt;br/&gt;asm-commons-2.1.jar
&lt;br/&gt;commons-logging-1.1.1.jar
&lt;/li&gt;
&lt;li&gt;Finally, you'll need to rename the commons-logging-1.1.1 jar to something else, like commons-logging.jar (thanks to Martin for &lt;a href="http://groups.google.com/group/google-appengine-java/browse_thread/thread/d88f23730971bb66/cfdfb4a504071e7d"&gt;this tip&lt;/a&gt;!)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Next, you'll need to configure your web.xml for Spring. In web.xml I added a catch-all mapping to my Spring dispatcher:
&lt;/p&gt;
&lt;div class="code prettyprint"&gt;&amp;lt;servlet&amp;gt;
	&amp;lt;servlet-name&amp;gt;dispatcher&amp;lt;/servlet-name&amp;gt;
	&amp;lt;servlet-class&amp;gt;org.springframework.web.servlet.DispatcherServlet&amp;lt;/servlet-class&amp;gt;
	&amp;lt;load-on-startup&amp;gt;1&amp;lt;/load-on-startup&amp;gt;

&amp;lt;/servlet&amp;gt;
&amp;lt;servlet-mapping&amp;gt;
	&amp;lt;servlet-name&amp;gt;dispatcher&amp;lt;/servlet-name&amp;gt;
	&amp;lt;url-pattern&amp;gt;/*&amp;lt;/url-pattern&amp;gt;
&amp;lt;/servlet-mapping&amp;gt;&lt;/div&gt;

&lt;p&gt;&lt;b&gt;WARNING: &lt;/b&gt;If you use a catch-all (/*) url-pattern, the application will not work in development mode (locally), but will work on the AppEngine server. I believe this is a known bug.&lt;/p&gt;
&lt;p&gt;For my dispatcher-servlet.xml: (also in /war/WEB-INF/)&lt;/p&gt;
&lt;div class="code prettyprint"&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;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"&amp;gt;

	&amp;lt;context:component-scan base-package="example.controllers" /&amp;gt;

	&amp;lt;bean id="viewResolver"
		class="org.springframework.web.servlet.view.InternalResourceViewResolver"
		p:prefix="/WEB-INF/views/" p:suffix=".jsp" /&amp;gt;

&amp;lt;/beans&amp;gt;&lt;/div&gt;

&lt;p&gt;You obviously want to change the base-package to whatever package you want. I use the InternalResourceViewResolver, and put all my views in /WEB-INF/views/. Finally, here's my (uninteresting) applicationContext.xml:&lt;/p&gt;
&lt;div class="code prettyprint"&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN"
    "http://www.springframework.org/dtd/spring-beans-2.0.dtd"&amp;gt;

&amp;lt;beans&amp;gt;

&amp;lt;/beans&amp;gt;&lt;/div&gt;

&lt;p&gt;Now we're all done with setup! Just create a controller and a view. I made a simple hello.jsp view that outputs the request parameter "name". Here's the controller:&lt;/p&gt;
&lt;div class="code prettyprint"&gt;package example.controllers.hello;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class HelloController {

	@RequestMapping("/hello/{name}")
	public String hello(@PathVariable String name, Model model) {
		model.addAttribute("name", name);
		return "hello/hello";
	}
}&lt;/div&gt;

&lt;p&gt;So there you have it. Spring up and running on Google App Engine. You can see it in action at &lt;a href="http://springexample.appspot.com/"&gt;http://springexample.appspot.com/&lt;/a&gt;, or you can get the source at &lt;a href="http://github.com/idris/spring-example-gae/"&gt;http://github.com/idris/spring-example-gae/&lt;/a&gt;. For now, this is all just a Hello Wold. I'll post more functionality later... Feel free to suggest topics in the comments!&lt;/p&gt;
</description>
				<pubDate>Sun, 19 Apr 2009 13:27:00 -0400</pubDate>
				<guid>http://www.ardentlord.com/apps/blog/show/829881</guid>
			</item>
		
	</channel>
</rss>

