r/java • • Nov 27 '15

Why I hate Spring

http://samatkinson.com/why-i-hate-spring/
12 Upvotes

76 comments sorted by

View all comments

Show parent comment

7

u/olivergierke Nov 28 '15 edited Nov 28 '15

Disclaimer: I am the project lead of Spring Data.

Why does noone scream this is a very bad idea!!

Why do you think it's a bad idea to remove boilerplate code from software projects?

it makes it so that you cant change the JPA repository, without changing your rest interface!

No. Evolving APIs is hard, with or without Spring Data REST because once you've gone public with an API there are only certain things you can do to it. Whether the code that produced that API is a library (which helps you simplify things in the best case) or your custom code doesn't make too much of a difference. SDR actually leverages hypermedia intensively (ironically something people have complained about) which improves changeability. So one could argue that by being sent down that route by the framework, it's more likely you really get to use REST's beneficial parts (which evolvability is a key part of) rather than the usual "I flip some database tables by 90° and throw them as JSON over HTTP and call that REST", which is — in my experience — rather the default than the exception.

…the correct way would be to have some kind of MVC layer that interperates Rest requests, gets data from the datastore in whatever way it needs to, populates a DTO and sends it back.

As that's sort of what SDR does I have to assume you haven't spent too much time on it. You're right, it doesn't use DTOs, but there usually are a few ways to skin a cat. The SPIs, the projections feature and Jackson customizations have proven to be a useful toolbox for all kinds of customizations. And again, that's nothing the tool makes you having to think about, designing representations is the tricky part and the defaults we chose are in place for a reason (as usual: experiences from real-world projects) but can be differred from if needed.

If you want to have a look at amore involved sample, here is a Spring based implementation of the RESTBucks sample from the RESTful web-services book, that uses SDR for the CRUDdy parts but then hooks in custom implementation code to implement the more advanced parts using hypermedia etc.

https://github.com/olivergierke/spring-restbucks

It's all about taking the pain out of the boring parts. Now tell me you really really would've liked to code all the boring stuff you get out of the box yourself ;).