6. Creating Spring Components

PROBLEM

In the course of developing web applications there is often a need to create data objects that aren't a part of the domain model. The data objects are referred to as data transfer objects (DTO), and they can be used throughout the application for passing data. When there isn't a close correlation between the domain objects and the views of the application, DTOs can be used for creating form backing objects.

SOLUTION

A Component is a Spring DSL artifact that defines a generic container for data. A component gets generated into an @Component annotated Spring component, a generic stereotype for Spring managed components with configurable scope. Components are typically used as data transfer objects (DTO) and form backing objects.

HOW IT WORKS

Steps for creating a Component:

  1. Right click the on a Model Package, and select New-->Component

  2. From the New Component Wizard, enter a common name for the component. The common name is for referencing the component from other artifacts. Click Finish