春季启动:错误要求在JpaRepository中实现所有方法

时间:2018-12-23 03:28:41

标签: spring-boot spring-data-jpa

为什么会这样?几个月前,当我在STS从事春季项目时,这并没有发生。 我已经在课堂上导入了以下内容:

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
    
<div class="container">
    <div class="row">
      <div class="col d-flex justify-content-center">
        <div class="d-flex flex-column">
          <div class="item"><img src="https://picsum.photos/500/500" class="rounded"></div>
          <div class="item"><i class="fas fa-caret-square-left fa-2x"></i></div>
        </div>             
    </div>
  </div>
</div>

enter image description here

以下是我的pom.xml:

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

1 个答案:

答案 0 :(得分:3)

自定义存储库必须是一个接口,并且必须从JpaRepositoryCrudRepositoryPagingAndSortingRepositoryMongoRepository扩展,因此请通过以下方式进行更新:

@Repository 
public interface UserRepository extends JpaRepository<User, Long> {....} 

参考

Official documentation on repositories core concepts