关于网友提出的“ spring boot不能注入JpaRepository接口,提示找不到bean”问题疑问,本网通过在网上对“ spring boot不能注入JpaRepository接口,提示找不到bean”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:
问题: 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 boot不能注入JpaRepository接口,提示找不到bean”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/4347916.html