Using Spring Data with MongoDB: Creating a Maven Project

First, we need to create a Maven project in Eclipse.

  1. Select File ➤ New ➤ Other.
  2. In the New window, select the Maven ➤ Maven Project wizard and click on Next as shown in Figure 10-1.

  1. The New Maven Project wizard gets started. Select the Create a simple project check box and the Use default Workspace location check box as shown in Figure 10-2. Then click on Next.

4. In Configure project specify the following settings and click on Finish as shown in Figure 10-3.

  • Group Id: com.spring.mongodb
  • Artifact Id: SpringDataMongo
  • Version: 1.0.0
  • Packaging: jar
  • Name: SpringDataMongo

A Maven project (SpringDataMongo) gets created as shown in Package Explorer as shown in Figure 10-4.

The Java Build Path for the project should include the Maven dependencies including the Spring Data MongoDB project dependency. Installing Spring Data MongoDB and other dependencies is discussed in the next section. We need to add some classes to the Maven project to use Spring Data with MongoDB. Add Java Classes listed in Table 10-1.

The Java classes in the Maven project are shown in Figure 10-5.

In subsequent sections we shall install and use the Spring Data MongoDB project. Unless noted otherwise, before running an application, App.java or CatalogService.java, drop the catalog collection in the local database if it already exists using the method db.catalog.drop() in Mongo shell.

>use local

>db.catalog.drop()

Source: Vohra Deepak (2015), Pro MongoDB™ Development, Apress; 1st ed. edition.

Leave a Reply

Your email address will not be published. Required fields are marked *