I'm a beginner to SpringBoot. I have used the methods findAll() and save() to read and create operation respectively, by extending CrudRepository which is an interface. Hence I couldn't find any implementation
My question is where and how exactly are these methods implemented?

- 235
- 3
- 8
1 Answers
There's no way to answer your question with just the information you've provided. That's not a bad thing. That's a very good thing. That's the power of interfaces and of Spring's most basic ability, dependency injection. The whole idea behind both of those concepts is that your code, and maybe even the programmer, doesn't know anything about the implementation of a particular interface. There can be a few or 100s of unique implementations of that interface, and each one of those means at least a slightly different answer to your question.
Another way to "answer" your question is to say "The implementation of the interface you're interacting with in your code is defined by whichever concrete implementation of that interface you've configured to actually perform that role.".
In the case of Spring Boot, the answer to your question is often defined by your application's package dependencies, usually defined via a Maven or Gradle project file. Here, for example, are the lines you'd add to a Gradle project definition to cause Spring Boot to implement your CRUD operations using JPA and MySQL:
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile("mysql:mysql-connector-java:5.1.13")
If you have a working app, then the answer to your question is probably determined by lines similar to these in your Maven or Gradle file or in the equivalent definition of your project per whatever method you are using to define it. If you don't have a working app, then maybe you haven't yet even chosen a backing implementation, and your question literally has no answer.
If you want a more definitive answer, why don't you post more details about your app, like the code, and more importantly, your Maven or Gradel project file.

- 21,719
- 5
- 26
- 44
-
I only just noticed @Strelok's comment about there being an existing question of the same or similar nature. The answer there backs up what I've said and provides much more detail about what MIGHT be implementing your CRUD interface. - I suggest you review that post, and I hope it answers your question more completely than I could. – CryptoFool Mar 10 '19 at 02:55
-
Yes there can be 100s of unique implementation. But findAll() would be a select * from
query. So I just want to view a general implementation where such code is implemented, not specific to my project. – user7098526 Mar 11 '19 at 09:08 -
It would only be such a query if the backing implementation is SQL. There's no reason it has to be. There is no place to look for "select * from
" until you define your backing implementation. - your backing implementation could be a NoSql database. Your backing implementation could be a Java HashMap. - Even if you're sure you want to use MySql, there are different ways of doing that. Look at Spring JPA. That will get you started. That's the most standard backing implementation. – CryptoFool Mar 11 '19 at 15:40 -
Check this out: https://spring.io/projects/spring-data-jpa. Look to the left side, and you'll see a list of all the things that can be behind a Spring Data interface. If you want a SQL back end, this document is the place to start. Go through a tutorial to set up a JPA database based on MySql. Then you'll be able to find the backing queries. I don't know specifically where they are, but you'd have a concrete question to ask then about finding them. – CryptoFool Mar 11 '19 at 15:48