Home  >  Q&A  >  body text

java - spring boot cannot inject the JpaRepository interface and prompts that the bean cannot be found

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 inherits JpaRepository, which should be the simplest example

There is only one package in total. SpringBootApplication and Controller are placed under the same package. There should be no ordering problems on the Internet.

伊谢尔伦伊谢尔伦2686 days ago1139

reply all(2)I'll reply

  • 黄舟

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

    StudentRepository is not registered

    reply
    0
  • 巴扎黑

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

    I solved it myself, the jpa package conflicted.

    reply
    0
  • Cancelreply