Setting Up a Spring MVC with AWS Project in Eclipse

Create the Spring MVC + AWS Project

I am running Eclipse Luna and added both the Spring Tool Suite (STS) and AWS plugins. I used the project wizard to first create a Spring MVC project.

Screen Shot 2015-03-19 at 2.46.43 PM

With the project created you will get your MVC dispatch servlet configured and even a basic home controller.

Now onto AWS. In your project properties, add the AWS SDK for Java library to your build path.

Screen Shot 2015-03-19 at 2.48.04 PM

Set up the Local DynamoDB Server

I am using DynamoDB, so let’s get a local DynamoDB server set up.

Install the DynamoDB Local Test Tool under Eclipse Preferences.

Screen Shot 2015-03-19 at 2.33.23 PM

In the AWS explorer, set your region to local.

Screen Shot 2015-03-19 at 3.06.07 PM

Now let’s see if it runs.

Screen Shot 2015-03-19 at 3.09.38 PM

Set up the Local Tomcat Server with AWS Libraries

Great. Now let’s get a local tomcat server set up for testing locally. We will need to add the AWS SDK libraries to the Tomcat classpath via catalina.properties.

 Create the First Domain Objects

Now let’s set up our first domain objects to persist to the local DynamoDB server. I’ll create an abstract User class and a EndUser child class using the DynamoDB Java annotations. There isn’t much here in the classes for now, but let’s just store username and password to get started.

 

 Create the Table in the DynamoDB Server

Now create the table in the DynamoDB server. You only need to specify the primary key.

Screen Shot 2015-03-20 at 12.50.13 PM

Screen Shot 2015-03-20 at 12.54.08 PM

The table should now show up in the AWS explorer.

Screen Shot 2015-03-20 at 12.54.27 PM

Let’s use the default Spring home controller to test saving an EndUser since it is already set up to be the default launcher. Make sure to set your AmazonDynamoDBClient to use your local server.

Persist Data to the DynamoDB Server

 

Now we are ready to run it! Select Run on Server and choose your Tomcat Server (that was configured with AWS above).

Screen Shot 2015-03-20 at 9.45.11 AM

And you should get the default Spring MVC home page.

Screen Shot 2015-03-20 at 12.55.48 PM

But that doesn’t show us if the user was created in the DynamoDB. To verify that, double click the User table in the AWS explorer. You should see the new entry in the User table. That’s it!

Screen Shot 2015-03-20 at 12.56.05 PM