问题: 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 studentList(){
        return studentRepository.findAll();
    }

}

StudentRepository 继承 JpaRepository,应该是个最简单的例子了

一共就一个包,SpringBootApplication和Controller都放在一个包下面,应该不会出现网上的顺序的问题


解决方案1:

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

解决方案2:

StudentRepository 没有注册

上一篇spring mvc,如果实体类的字段都是大写字母,http请求时,数据绑定不上,请问为什么?
下一篇SWT中鼠标放上去出来一个提示框 类似于这个功能是怎么实现的?
明星图片
相关文章
《 spring boot不能注入JpaRepository接口,提示找不到bean》由码蚁之家搜集整理于网络,
联系邮箱:mxgf168#qq.com(#改为@)