简体   繁体   中英

Spring data repository methods implementation

I'm working in a personal web project and I would like to use Spring Data and JPA. I found this nice blog entry in springsource.com and I've spent several hours trying to understand how this work and why they do it this way. I need help with two questions mainly:

  1. Why is necesary to use Service and ServiceImpl classes. That seems like a typical JPA 2 implementation but using Spring Data underneath with an Autowired repository. This really confuse me. Why not use the repository directly?
  2. The writer defines a pair of new methods in CustomerRepository but there isn't any implementation. He continues implementing CustomerService that it's not related with the repository. I've seen this in many sites but I don't understand how it works.

As I said I've been looking for a good article to find answers to my questions but most of them seem that are following these one. I've also checked github code of the article's project but it's uncomplete. I hope you can help me.

The point of the blog post is to talk about spring-data repositories. So it doesn't elaborate on why services are necessary.

They are because a typical business method will deal with several DAOs/Repositories, in a single transaction. For example, transferring money might include calling the AccountRepository, the AudiRepository and the CustomerRepository. The service's main goal is to provide transactional business methods to the presentation layer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM