Using Spring in a standard Java application

In this recipe, we will build a standard Java application (not a web application) using Spring. We will:

  • Create a new Maven project
  • Add Spring to it
  • Add a class to configure Spring
  • Add a User class
  • Define a User singleton in the Spring configuration class
  • Use the User singleton in the main() method

How to do it…

In this section, we will cover the steps to use Spring in a standard (not web) Java application.

Creating a new Maven project in Eclipse

  1. In Eclipse, in the File menu, select New | Project....
  2. Under Maven, select Maven Project and click on Next >.
  3. Select the Create a simple project (skip archetype selection) checkbox and click on Next >.
  4. For the Group Id field, enter com.springcookbook. For the Artifact Id ...

Get Spring Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.