搜尋

首頁  >  問答  >  主體

java - spring boot不能注入JpaRepository接口,提示找不到bean

Field studentRepository in com.example.demo.StudentController required a bean of type 'com.example.demo.StudentRepository' that could not be found.

Action:

Consider defining a bean of type 'com.example.demo.StudentRepository' in your configuration.

@RestController
public class StudentController {

    @Autowired
    private StudentRepository studentRepository;

    @GetMapping(value = "/findAll")
    public List<Student> studentList(){
        return studentRepository.findAll();
    }

}

StudentRepository 繼承 JpaRepository,應該是個最簡單的例子了

一共就一個包,SpringBootApplication和Controller都放在一個包下面,應該不會出現網上的順序的問題

伊谢尔伦伊谢尔伦2798 天前1221

全部回覆(2)我來回復

  • 黄舟

    黄舟2017-06-12 09:29:23

    StudentRepository 沒有註冊

    回覆
    0
  • 巴扎黑

    巴扎黑2017-06-12 09:29:23

    我自己解決了,jpa的包包衝突了。

    回覆
    0
  • 取消回覆