• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

UnsatisfiedDependencyException

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
now showing this log 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!
 
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
     
    reply
      Bookmark Topic Watch Topic
    • New Topic