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

阅读 10.6k
3 个回答

StudentRepository 没有注册

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

新手上路,请多包涵

可能是你的实体类没有添加@Entity 注解

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题