Domain Driven Design (DDD) enables you to design your applications in a more object oriented fashion. Current JEE development approaches promote the use of JPA/Hibernate objects as data storage elements and to supplement an extra service layer on top of those JPA objects. This leads you to structure your application in a more procedural manner. DDD allows you to code your business logic mostly in your domain objects. Using DDD techniques minimizes the extra service layer usage and complexity so that you can get a simpler design and speed up the development.

I will discuss about a way to implement DDD with Spring JDBC. Let me explain the main structures in my implementation;

The beans "txManager" and "dataSource" set transaction configuration. It is required to use @Transactional annotations for your methods and classes. The bean "dateUtil" is a simple utility class for formatting dates. "Book" represents a domain object. "bookRepository" is an object to retrieve and save "Book" objects.

"BookRepository" is a repository object performing database operations. "findBooks()" fetches all the book information from the database. Please note that in order to do that, it retrieves a "Book" object from Spring context by calling "createBean()" method. Spring creates, inits and returns a managed "Book" bean."insert()" just adds another "Book" object to the database. "init()" prepares the database for the application.

The sample application starts by calling main method of "Start" class.

The goal of that code snippet is to format "dateAdded" property of a "Book" object. To do that, a "Book" object uses "DateUtil" object, which is injected to it to format the date. You can get formatted stringby calling "formatDateAdded()" method of a "Book" object without touching any "DateUtil" object.

You can find the related source code as an attached zip file in Resources section.