0

I am getting this error whenI lauch

Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userService': Unsatisfied dependency expressed through field 'userRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository' defined in xxxxxxx.Repository.UserRepository 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 xxxxx.Model.User xxxxx.Repository.UserRepository.findByEmail(java.lang.String)! Reason: Validation failed for query for method public abstract xxxx.Model.User xxxxx.Repository.UserRepository.findByEmail(java.lang.String)!; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract xxxx.Model.User xxxxx.Repository.UserRepository.findByEmail(java.lang.String)

This is m repository:

public interface UserRepository extends JpaRepository<User, Long> {

     @Query("SELECT u FROM User u WHERE u.email = ?1")
     public User findByMail(String mail);
}

Whe is rong here?

1
  • You don't need the @Query assuming the field is named mail else rewrite your method to findByEMail. Please add the full-stracktrace as well as your User class. Commented Feb 18, 2022 at 9:15

2 Answers 2

1

You can try this one:

public interface UserRepository extends JpaRepository<User, Long> {
     public User findByMail(@Param("mail") String mail);
}
Sign up to request clarification or add additional context in comments.

Comments

0

try this

 @Query("SELECT u FROM User u WHERE u.email =:mail",nativeQuery=true)
 public User findByMail(String mail);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.