spring data rest vs spring data jpa

天涯浪子 提交于 2019-12-03 07:22:34

问题


I have had a look at the following question

What are the advantages of using Spring Data REST over Spring Data JPA?

It doesn't quite cater to my needs. My DB is on MYSQL, I chose Spring-Data-JPA implementation. What are all the added advantages that REST can give me which I wont find in simple Spring-Data-JPA? For example if tomorrow, I decide to implement a cache b/w my business and Database module, in which case would I have to write lesser code? Which would be easily configurable? Which would be more flexible and how?

Also, if I am using both REST and JPA in a new application, what design principles do I break?

I am looking forward to the answers from an architecture perspective. Thanks in advance.


回答1:


Basically I think your question is not completely to the point. I think you have not completely found your way through the spring project jungle - so I try to give a little orientation here.

Spring-data-jpa is the spring way to access data using JPA. You could use spring-data-rest on top of spring-data-jpa to create a REST-API layer with no code on top of your repositories and entities.

And what spring-data-rest can do for you is just amazing. It is the fastest way to create a REST API on top of your JPA layer. And it is also highly customizable. But I think it has it's limits. The most significant weakness is the tight coupling between entities and API. Usually you would like to have a little decoupling between these layers. But it is a great piece of software. If you need to be fast and want to write the minimal amount of code go for spring data rest.

A spring alternative to spring-data-rest is using spring MVC directly to create a REST API on your own. Spring-data-jpa would still be used to implement the data access layer. Spring MVC is very powerful and is used by spring-data-rest under the hood. This gives you full control of the REST layer.

I also want to mention spring HATEOAS - it is just a module on top of spring mvc and it gives you the tools to create a hypermedia driven REST API - so you can go for a maturity level 3 of the Richardson Maturity Model - it is also used by spring-data-rest internally.



来源:https://stackoverflow.com/questions/33422849/spring-data-rest-vs-spring-data-jpa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!