Friday, December 30, 2011

Hello World - Spring 3.0 STS

This is to lay out the very bare details needed to create a "Hello Word" application using Spring 3.0 STS.

I actually had quite a bit of difficulty locating a tutorial on how to do it. Unfortunately, the flagship screencast at the site shows the source code for a project that exercises various aspects of - but doesn't show how to set up your own project. This leaves you struggling a bit for tutorials that tell you how to actually work the controls of this monster.

Almost by accident, I stumbled across a couple of tutorials which were enough to get me started. The first one, which I've unfortunately lost, basically showed how to run the server and what the default source code looked like. Unfortunately, it didn't work. But at least it got me started on the right track.

A better tutorial was this:

http://blog.springsource.org/2011/01/04/green-beans-getting-started-with-spring-mvc/

I *almost* works out of the box - you just need to do a *little* bit of debugging.

Anyway, without further ado, here are the steps to follow:

1. From Eclipse STS, type file > new Spring Template Project (then choose) SpringMVCProject

2. If you follow the tutorial, you'll give the project a name like "baremvc" and a package name of "xyz.sample.baremvc".

NOTE: Watch out for caps on the project name - it appears to be the url name to call, and is case-sensitive. I need to test this.

3. Because the blog is about a year old, there are slight variance in code he suggests and the code that is generated. In fact, you can leave the code as generated for home.jsp and HomeController.java.

If you do use the code for "HomeController" as provided, make sure to make the return line "return "home" and not

return "WEB-INF/views/home.jsp";

4. Now, run it on the server. Right click on the project and select "run on server".

5. Enter http://localhost:8080/baremvc

You *should* be ok. One thing to watch out for is if you set up multiple project - I think only one of them can have a controller set up with a "/". The rest of them must need something extra. I'll check that.

No comments:

Post a Comment