RSS Feed Subscribe to RSS Feed


Spring MVC Hello World with Continuous Deployment

Oh dear, yet another ‘Hello World!’. But although the functionality is trivial, this little SpringMVC project is complete enough for me to use as a template to bootstrap more complex projects. It consists of:

  • HTML/JSP client
  • SpringMVC server using a Controller/Service/DAO design
  • Maven for build and dependency management

This is an updated version of an older project I created, with the following enhancements:

  • Added a full suite of automated tests (unit, integration and browser based)
  • Added placeholders for JavaScript and images (both can be a little tricky to put in the correct place with SpringMVC)
  • Incorporated into a continuous deployment environment

More details below, but you can find the full source code on this GitHub repository and the deployed app at


Although all the code is very simple, it all has automated tests in place for when things start getting more complicated:

The tests are broken down into unit and integration tests:

  • Unit tests are run as normal by maven using the Surefire plugin (and hence invoked as part of a ‘mvn test’)
  • Integration tests are run as follows:
    • Using the Failsafe Plugin. The Failsafe Plugin is designed to run integration tests. I have used it as described here and by default it will include all tests ending in ‘’. In short, integration tests will run when ‘mvn install’ is invoked.
    • Secondly, our integration tests include Selenium tests, which require that our server is running. So how can we ensure that as part of an isolated maven build? The answer is by having maven start, stop and deploy to a simple app server as part of testing. I am using Jetty as the app server since it is lightweight and easy to use with maven via the the Maven Jetty Plugin. See the ‘Automatic execution of the plugin‘ section.

Using JavaScript and images with SpringMVC

Placing JavaScript and image files in the correct location so that they can correctly be served by SpringMVC can be a little tricky. The approach I used was the one described in the Spring docs.
This is also the approach used in the very useful spring-mvc-3-showcase.

Continuous Deployment

Finally, I added a Continuous Integration environment using CloudBees – a Java Platform-as-a-Service (PaaS).

  1. First, using Cloudbees DEV@cloud, I setup a Jenkins build server and have it monitor my GitHub repository, automatically building and running all tests any time a check-in is detected.
  2. Second, using Cloudbees RUN@cloud, I have jenkins automatically deploy to ‘the cloud’, meaning the war artifact built by Jenkins is automatically deployed to a remote server.

Although I did have one slight hiccup [] deploying to CloudBees, I got it all working without too much difficulty.
I have blogged about using CloudFoundry in the past, and also experimented with an Amazon AWS EC2 approach, but the Jenkins integration and incredibly simple deployment option available with CloudBees made it the easy choice in this case.

Again, you can find the deployed app at

Tags: , , , , , , , , , , ,

2 Responses to “Spring MVC Hello World with Continuous Deployment”

  1. sabram |

    Update: Migrated Jetty from port 8080 to 9090 (since tomcat often runs on 8080)

  2. Alan |

    First of all.. excellent job!
    It would be better if it had spring security and the templates for bootstrap. Regards, Alan

Leave a Reply