What is implementation class of org.springframework.data.jpa.repository.JpaRepository interface?
no implementation class on these interface is defined. So what actual instance is injected into info.saladlam.example.spring.noticeboard.service.MessageServiceImpl?
That instance is a proxy, with target class instance org.springframework.data.jpa.repository.support.SimpleJpaRepository and many advice/advisor/interceptor is attached. One important interceptor is org.springframework.data.repositor .QueryExecutorMethodInterceptor.
Definition of info.saladlam.example.spring.noticeboard.repository.MessageRepository
public interface MessageRepository extends JpaRepository<Message, Long> {
@Query("SELECT m FROM Message m WHERE m.approvedBy IS NOT NULL AND m.publishDate <= :at AND (m.removeDate IS NULL OR m.removeDate > :at) ORDER BY m.publishDate DESC")
List<Message> findPublished(@Param("at") LocalDateTime at);
@Query("SELECT m FROM Message m WHERE m.approvedBy IS NULL ORDER BY m.publishDate DESC")
List<Message> findWaitingApprove();
@Query("SELECT m FROM Message m WHERE m.owner = :owner ORDER BY m.publishDate DESC")
List<Message> findByOwner(@Param("owner") String owner);
}
and its parent interface org.springframework.data.jpa.repository.JpaRepository
@NoRepositoryBean
public interface JpaRepository<T, ID> extends PagingAndSortingRepository<T, ID>, QueryByExampleExecutor<T> {
List<T> findAll();
List<T> findAll(Sort sort);
List<T> findAllById(Iterable<ID> ids);
<S extends T> List<S> saveAll(Iterable<S> entities);
void flush();
<S extends T> S saveAndFlush(S entity);
void deleteInBatch(Iterable<T> entities);
void deleteAllInBatch();
T getOne(ID id);
@Override
<S extends T> List<S> findAll(Example<S> example);
@Override
<S extends T> List<S> findAll(Example<S> example, Sort sort);
}
For example, when a method findAll() defined in JpaRepository is called, as result method findAll() of SimpleJpaRepository is called. And when a method findWaitingApprove() defined in MessageRepository is called, interceptor. support.RepositoryFactorySupport.QueryExecutorMethodInterceptor is involved. In method org.springframework.data.repository.core.support.RepositoryFactorySupport.QueryExecutorMethodInterceptor.doInvoke()
@Nullable
private Object doInvoke(MethodInvocation invocation) throws Throwable {
Method method = invocation.getMethod();
Object[] arguments = invocation.getArguments();
if (hasQueryFor(method)) {
return queries.get(method).execute(arguments);
}
return invocation.proceed();
}
queries is a map, which store org.springframework.data.jpa.repository.query.JpaQueryMethod instance with key method defined in MessageRepository.
Reference
이 문제에 관하여(What is implementation class of org.springframework.data.jpa.repository.JpaRepository interface?), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/saladlam/items/b166c6771388b6fa995b텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)