Hello World Web App using Spring Annotations Part 1

I’ve used the Spring Framework to build web applications for several years now.  I learned the old-fashioned way (if there is such a thing) of Spring MVC: SimpleFormController, AbstractController, Wizard controllers, and the rest of the MVC package.  Recently though, I had a chance to start a project from ground zero and upgraded to Spring 3.0.0.  It was also a good chance to learn about Spring Annotations and how they could make my life easier.

This is the first of what I hope to be a series of posts about building web applications using the Spring Framework.  If you are completely new to Spring, this post will hopefully help you get over the initial hump of learning Spring.  If you are familiar with Spring, but not with annotations for web applications, these posts will give you some examples.

Like most of the Java projects on this site, I’ll be using Eclipse, Maven, and the Sysdeo Tomcat plug-in.  You may want to read the Using Java Projects and Setting up Sysdeo postings for more information.

In this first post, we will build a version the classic Hello World as a web application using Spring.  Here are the requirements and goals:

  • Use a Spring MVC controller and a JSP page to show a simple message
  • Use Spring Annotations instead of the old MVC package
  • Minimum amount of XML configuration (in fact, it is 27 lines of XML in the end)
  • The message must come from the controller, not be hard-coded into the JSP
  • Package the web application into a WAR file (using Maven)

Continue reading Hello World Web App using Spring Annotations Part 1

Using Live Writer with the WordPress SyntaxHighlighter plugin

Since this is likely to be a code-heavy blog and I had a bit of trouble getting the syntax highlighting to work with Live Writer, this seems to be a good first blog post.

In the end I decided to use one WordPress plugin and one Live Writer plugin.  They seem to work great together so far.  Both plugins make use of brilliant SyntaxHighlighter package by Alex Gorbatchev (you don’t need to install this.. it comes with the WordPress plugin).

The WordPress plugin is called SyntaxHighlighter Evolved by Viper007Bond.  Install this plugin into WordPress the usual way (wp-admin > Plugins > Add New).  After installing and activating the plugin, go into the plugin settings for SyntaxHighlighter Evolved and check the box that says "Always load all language files".  Save the new configuration.

The Live Writer plugin is called the PreCode Code Snippet Manager by Anthony Bouch.  Install this plugin into Live Writer.

I’ve tried several of the Live Writer code snippet plugins, and this is the only one I have found that correctly handles the PRE tags and doesn’t munge up my double quote symbols.

Once you have both plugins running, you can insert code into your blog posts from directly inside Live Writer.  Simply click on "PreCode Snippet" from the Live Writer sidebar, set your language and options, and insert your code!  The results looks like this:

// PHP Comment
function phpFunction() {
    echo "I'm a PHP Function";
}

 

// Java Comment
public class SomeJavaClass {

    public static void main(String args[]) {
        System.out.println("Java foo!");
    }

}

 

<!-- XML Comment -->
<SomeXMLObject>
    <SomeField someAttribute="foo">
        <SomeElement>Foobar!</SomeElement>
    </SomeField>
</SomeXMLObject>