Search code examples
javaspring-dataspring-data-jdbc

How and Where was the my repository interface instanced by SimpleJdbcRespository?


I created a custom repository interface that extended by CrudRepository. I just used @EnableJdbcRepositories in StartApplication.

When I test a method from my custom repository, such as save(T t) I seen it be instanced by SimpleJdbcRespository.class.

I interested it, I want to know how and where was the SimpleJdbcRespository created and have implemented my custom repository interface.

Which line of code should I debug?


Solution

  • All Spring Data JDBC repositories get created by JdbcRepositoryFactory which uses SimpleJdbcRepository as the implementation for the CrudRepository methods.

    For additional methods in the repository interface JdbcQueryLookupStrategy is consulted which determines how to get the right query for a method to execute in the form of a RepositoryQuery.

    Currently there is just implementation of that: JdbcRepositoryQuery

    If something doesn't work as expected with the execution of such a method. JdbcRepositoryQuery.execute(Object[] objects) is a good start for debugging. You probably also want to look up how the executor used in there get constructed.