您的位置:首頁技術文章
文章詳情頁

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

瀏覽:91日期:2023-11-04 14:09:58

問題描述

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.

@RestControllerpublic class StudentController { @Autowired private StudentRepository studentRepository; @GetMapping(value = '/findAll') public List<Student> studentList(){return studentRepository.findAll(); }}

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

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

問題解答

回答1:

StudentRepository 沒有注冊

回答2:

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

標簽: java
国产综合久久一区二区三区