首页  >  问答  >  正文

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都放在一个包下面,应该不会出现网上的顺序的问题

伊谢尔伦伊谢尔伦2686 天前1142

全部回复(2)我来回复

  • 黄舟

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

    StudentRepository 没有注册

    回复
    0
  • 巴扎黑

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

    我自己解决了,jpa的包冲突了。

    回复
    0
  • 取消回复