Contents
Can we use @repository instead of @service?
2 Answers. According to documentaion @Repository , @Service , @Controller are all synonyms. They all are just specializations of @Component annotation. So, generally, they can be used one instead of other.
Is a controller a service?
Controller Services are shared services that can be used by reporting tasks, processors, and other services to utilize for configuration or task execution. Controller Services defined on the controller level are limited to reporting tasks and other services defined there.
What is the difference between @component and @service?
@Component is a generic stereotype for any Spring-managed component or bean. @Repository is a stereotype for the persistence layer. @Service is a stereotype for the service layer. @Controller is a stereotype for the presentation layer (spring-MVC).
Which is the responsibility of the controller of a repository?
It’s the responsibility of your controllers. Your repositories should return domain objects and the client of the repository can decide if it needs to do the mapping. By mapping the domain objects to view models (or something else) inside a repository, you prevent the client of your repositories from getting access to the underlying domain object.
When to use domain objects in a repository?
Your repositories should return domain objects and the client of the repository can decide if it needs to do the mapping. By mapping the domain objects to view models (or something else) inside a repository, you prevent the client of your repositories from getting access to the underlying domain object.
Is it good practice to use one controller from another?
In general, you won’t use one controller from another one since: Controllers usually return a result of a type intended to be used by the MVC framework.
Can a repository return view models or DTOs?
Once again, a repository is like a collection of domain objects. So it should not return view models/DTOs or anything that is not a domain object. I’ve seen many students using AutoMapper inside their repository methods: