Let's split that error over multiple lines to make it more readable:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'studentController': Unsatisfied dependency expressed through field 'service';nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'studentService': Unsatisfied dependency expressed through field 'repo';nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'studentRepository' defined in com.example.emp.repository.StudentRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Invocation of init method failed;nested exception is org.springframework.data.repository.query.QueryCreationException: Could not create query for public abstract java.util.List com.example.emp.repository.StudentRepository.findbystudentname(java.lang.String)! Reason: Failed to create query for method public abstract java.util.List com.example.emp.repository.StudentRepository.findbystudentname(java.lang.String)! No property findbystudentname found for type Student!;nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.List com.example.emp.repository.StudentRepository.findbystudentname(java.lang.String)! No property findbystudentname found for type Student!
So the
studentController bean cannot be created because its
service field cannot be injected.
That's because the
studentService bean cannot be created because its
repo field cannot be injected.
That's because the
studentRepository bean cannot be created because some
init method throws an exception.
That's because method
findbystudentname of repository
StudentRepository does not work like you think it should.
I assume that
StudentRepository is an interface, and you added method
List<Student> findbystudentname(String studentname), hoping that Spring would automatically create a proper implementation for you. The issue is in the use of all lowercase. You want to find all students by student name, so you need to tell Spring that:
findByStudentname if
Student has a property
studentname,
findByStudentName if it has property
studentName. Because you want more than one, you may have to tell Spring that as well:
findAllByStudentname /
findAllByStudentName.
Because you're now missing capital methods, Spring can't translate the method name into a query and therefore tries to find students where property
findbystudentname matches the given argument.
So in short: because of the wrong use of case, Spring uses (JPQL queries)
SELECT s FROM Student s WHERE findbystudentName = :studentname and not
SELECT s FROM Student s WHERE studentName = :studentName.