2

I've used Spring Data Repository for basic CRUD operations on multiple data stores(relational databases, mongodb and elasticsearch). As per my understanding, it doesn't require the user to provide an implementation of the Repository and it works like a charm.

How does Spring Data generate the actual implementation of the Repository? At what phase it is done and how it is done?

I am asking this in order to generate implementation classes for my custom interfaces using the same approach.

  • 1
    Check out [this](http://stackoverflow.com/questions/23563252/how-to-see-the-repository-implementation-generated-by-spring-data-mongodb) answer on the same subject. – rorschach Aug 30 '16 at 11:35
  • So the implementation class is there and it's not auto generated? Is it just binded at runtime via proxy? –  Aug 30 '16 at 11:40
  • Looks like it. The comment author works for Spring. – rorschach Aug 30 '16 at 11:44
  • 2
    Spring Data doesn't generate the implementation of Repository, at runtime Spring-Data generate a Interface-Proxy with `java.lang.reflect.Proxy`. The calls to this Interface will be handle by a `InvocationHandler`. It intercepts all invocations and produces the response. I coded a [simple utility][1] to mapping properties as an object, I used this strategy. [This class][2] contains the key of your question. [1]: https://github.com/dperezcabrera/sconf4j [2]: https://github.com/dperezcabrera/sconf4j/blob/master/src/main/java/com/github/dperezcabrera/sconf4j/factories/FluentInterfaceFactory.java – David Pérez Cabrera Aug 30 '16 at 11:46

0 Answers0