Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Spring implements to kinds of Repository interface

I’m trying to study Spring more specific Spring Data but i have a question about the use of interface Repository and its derivatives classes and i asking you help for clarify them.

@Repository
public interface GuestRepository extends CrudRepository<Guest, Long>, 
         {}

For example i see this code example extends CrudRepository but i see the using of extends keyword but no implements. why ? I thought that extends is for sub classes or if i using abstract classes and implements for interfaces.

the other question trying to test another cases i try to extends from two classes (i know java not allow multiple) but java allowed me to do it.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

@Repository
 public interface GuestRepository extends CrudRepository<Guest, Long>, 
 PagingAndSortingRepository<Guest, Long> {}

And i see when i try to use some methods the ide shows to me without any problems and i try to execute i bring to me the data i request to it

enter image description here

So i’m kinda confused, when i talk extends java not allow extend from to or more classes but in this case does, but CrudRepository and PagingAndSortingRepository are interfaces so it should be with implements keyword. maybe some technnical concept in spring or java perhaps unknown to me.

In other post i see that is not posible create a class with two kind of repository but i can’t find any information about that.

I appreciate any help, thanks in advance

>Solution :

Interfaces CAN extend other interfaces, thus extends (GuestRepository is an interface)

classes implements interfaces, thus implements

You are not implementing anything here, sice Spring AOP will do "the implementation of queries" for you based on method names. This is kinds of Spring magic and is not Java specific. Using it as an example or reference to OOP and polymorphism in Java is rather bad.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading