Adding a Repository component
We’ll use the bottom-to-top approach to add a @Repository
component. Let’s start implementing the domain layer with a @Repository
component. We’ll implement the service and enhance the @Controller
component in subsequent sections accordingly. We will code the @Repository
component first, then use it in the @Service
component using constructor injection. The @Controller
component will be enhanced using the @Service
component, which will also be injected into the Controller using constructor injection.
The @Repository annotation
Repository components are Java classes marked with the @Repository
annotation. This is a special Spring component that is used for interacting with databases.
@Repository
is a general-purpose stereotype that represents both DDD’s Repository and the Java Enterprise Edition (JEE) data access object (DAO) pattern. Developers and teams should handle repository objects based on the underlying approach...