Skip to content
Model centric tools for Spring development Community portal
Skyway PerspectivesModel driven delivery

MyEclipse for Spring

Code Reference: CustomerServiceImpl.java

The service implementation behind the customer screens. This page covers its transaction settings and its calls to the data layer.

Four stacked application layers for Spring MVC and Spring Web Flow
Figure 27. The service implementation owns the transaction boundary.

CustomerServiceImpl implements the customer service interface and owns the transaction boundary. It calls the data access object, applies the small amount of business logic in the sample and returns plain Java types.

Transaction settings

The class is marked read only at the type level. Write methods override the setting with a read write transaction. This pattern keeps read paths fast and makes writes explicit. Start with one transaction per public write method and widen it only when a use case truly spans several operations.

Business logic

  • Normalise. Trim the name and lower case the email before saving.
  • Check uniqueness. Reject a save when another record already uses the email.
  • Default status. Set a new record to active when no status is supplied.
  • Return results. Return the saved record so that the caller can show the assigned key.
Testable by design. The service depends on an interface, so a test can pass a stub data access object. The generated test starter covers the save and find operations.

Keep the service free of web types. It should not know about requests, sessions or views. That separation lets the same service serve a JSP screen, a GWT client and a scheduled job.