3

Hy,

I have the next code in Spring

    @Repository
     public interface UserRepository extends CrudRepository<User, String>,     
         UserRepositoryExtension<RosterUser> {
      ...any custom spring JPA methods...

   }

Extension Interface:

    public interface UserRepositoryExtension <T> {
       public T put(T entity);
   }

Implementation of Extension interface

    public class UserRepositoryExtensionImpl implements       
     UserRepositoryExtension<User> {
 @Autowired
EntityManager entityManager;



@Override
public User put(User user) {
    entityManager.....(any logic here)
}...

}

I knew that Spring was able to create an inplementation of the UserRepository+CrudRepository interface methods in inyection time but what I dont get is:

  1. how spring creates these implementations and combine them with my implementation of UserRepositoryExtensionImpl(what happens under the hood?)

  2. How Spring knows what entityManager to use in the implementation class of UserRepository+CrudRepository it creates in injection time? It takes the entityManager from the context or from the class UserRepositoryExtensionImpl where an entityManager is declared?

Thanks

1

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.