|
|
-- Note: If you just want the nitty gritty without my blabbing, ignore the first paragraph --
So last week I got the inspiration to try out Google App Engine after reading about the new Java support. 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 "autoshoppe" example, which is a little incomplete in terms of setup and what libraries you need. Ironically, Spring Source's post about App Engine was talking about using Groovy, not Spring. Finally I found a blog entry by Sikeh. 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.
Here's how you'll need to setup the directory structure:
Next, you'll need to configure your web.xml for Spring. In web.xml I added a catch-all mapping to my Spring dispatcher:
WARNING: 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.
For my dispatcher-servlet.xml: (also in /war/WEB-INF/)
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:
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:
So there you have it. Spring up and running on Google App Engine. You can see it in action at http://springexample.appspot.com/, or you can get the source at http://github.com/idris/spring-example-gae/. For now, this is all just a Hello Wold. I'll post more functionality later... Feel free to suggest topics in the comments!
Categories: None
The words you entered did not match the given text. Please try again.

cheolho says...
WARNING: If you use a catch-all (/*) - I got this working in hosted mode but found other issues with Jetty. Can I ask what happens when you try to use this from your demo ? Try enabling logging for spring, and see what dispatcher output is. I will address this in my next blog, and show what i had to do to get it working. But from what you have in your demo .. this should work.




Idris says...
Oh, and the Spring error messages:
WARNING: No mapping found for HTTP request with URI [ /index.htm ] in DispatcherServlet with name 'dispatcher'
Apr 22, 2009 10:22:12 PM org.springframework.web.servlet.DispatcherServlet noHandlerFound
Apr 22, 2009 10:24:12 PM org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [ /WEB-INF/views/hello/hello.jsp ] in DispatcherServlet with name 'dispatcher'




Max Harper says...
Short answer: get rid of the asterisk in the /* url-pattern. This works locally; not confirmed on a live AppEngine instance yet.





Oops!
Oops, you forgot something.