DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Coding
  3. Frameworks
  4. Enterprise Spring Best Practices Part 2: Application Architecture

Enterprise Spring Best Practices Part 2: Application Architecture

Gordon Dickens user avatar by
Gordon Dickens
·
Jul. 28, 12 · Interview
Like (0)
Save
Tweet
Share
17.25K Views

Join the DZone community and get the full member experience.

Join For Free

This post presents a look at the overall application components and architecture of the Spring framework

Application Domains



Our application components break down into two fundamental categories, the System and Problem Domains.
  • System Domain – infrastructure components, the plumbing, this is Spring’s sweet spot!
  • Problem Domain – business components, typically use-case driven, this is what most of developers are paid to solve


Application Layers



Application components (beans) should be separated into distinct layers, and categories.




Bean Layers
  1. Controllers (for MVC, System Domain)
  2. Services (Problem Domain)
  3. Repository (System Domain)
Other Bean Categories
  • Data Transfer Objects (Problem Domain)
  • System Functions (System Domain)


Controller Beans



More on Controllers in an upcoming blog on Enterprise Spring Best Practices MVC blog – TBD


Service Beans



Service Beans are Problem Domain components. These are the MOST significant in the application. Service beans are the Fundamental component of SOA.
  • These are POJOs
  • Always defined from interfaces
  • NEVER include infrastructure components
  • NO import of Spring or utility libraries
  • NO infrastructure annotations
  • Always declare transaction boundaries by public functions
  • Create implementation/concrete classes in a sub-package named internal

Spring annotations can be very useful for services, useful annotations are @Service and @Transactional. To abstract away the infrastructure from the business services, create a project specific meta annotation.

Custom Meta Annotation
package com.gordondickens.service.annotation;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Service
@Transactional
public @interface AppService {
    String value() default "";
}
Meta Annotation Use
...
@AppService
public class MyClass() {
  ...
}


Repository Beans



Repository beans are in the System Domain. More on this in Enterprise Spring Best Practices ORM blog – TBD
  • DO NOT contain business logic
  • Do use Spring and JPA annotations
  • Should be considered disposable


Data Transfer Beans



Data Transfer Objects (DTO) are the fundamental objects in and out of our system. DTOs are simple public POJOs that receive and send data as a logical set.
  • Always Public Beans
  • Annotate with JAXB2 Annotations


Conversion Beans



Spring provides a rich conversion registry at it’s core. The conversion service in Spring is based on the original Bean Specification PropertyEditor.

PropertyEditors are focussed on String data into and out of our application.

The Spring class org.springframework.beans.PropertyEditorRegistrySupport shows the built in String <–> object classes. Which we use, usually without knowledge, in our applications. When we configure our applications with XML and send in property values, Spring uses reflection to determine the argument type, if that type is not a String, Spring looks for a PropertyEditor that can convert from String to the target type. We also can create our own PropertyEditor’s and register them for types such as US Social Security Number or Telephone Number. See: Craig Wall’s Spring in Action, 3rd Ed for examples.

  • Primitive wrapper types: Long, Integer, etc
  • Collection types: List, Property, Set, Map, etc.
  • Arrays
  • Utility types: URL, TimeZone, Locale, etc.

Spring 3.0 introduced the Conversion service providing us the ability to register a conversion service for object <–> other conversion. To use the conversion registry, we can register a conversion class that will automatically convert to/from MyObject <–> MyOtherObject. See Using Spring Customer Type Converter Blog.


Further Reading


  • Enterprise Spring Best Practices – Part 1
  • Enterprise Spring Best Practices – Source Code
  • FREE Spring Framework PDF (848 pages)
  • Craig Wall’s Spring in Action, 3rd Ed

 

Spring Framework application Architecture

Published at DZone with permission of Gordon Dickens, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • A Beginner's Guide to Back-End Development
  • How to Secure Your CI/CD Pipeline
  • Handling Automatic ID Generation in PostgreSQL With Node.js and Sequelize
  • Handling Virtual Threads

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: