Search code examples
javaspringspring-dataspring-data-rest

How to use Spring-data-rest for replacing ResourceAssemblerSupport


There are JPARepository in repository layer being called from Service Layer returning Entity to Spring MVC Controller layer. Controller will receive HTTPRequest as HATEOAS Resource. This is followed by a to and fro conversion from Resource to Entity and back to Resource with added links in ResourceAssemblerSupport.

Everything is in place and here is a link to what Just outlined above.

In between these, there are XML driven Spring configurations

Now there comes Spring-Data-Rest project which says it bridges the boilerplate code between JPARepository to HATEOAS ResourceAssemblerSupport using HAL specification. In that regard, how can Spring-Data-Rest let me get rid of to and fro conversion only in above setup ( ResourceSupport and ResourceAssemblerSupport ) ?


Solution

  • Spring-Data-Rest framework is based on Repositories. That means all logic that is in your service layer need to be modelled after SDR events. As long as you follow above two critical steps resource rendering into HAL content is just out of the box. If needed, much more customizations can be done using SDR annotations.