My program is not working after implementing changes for exception handling as explained in module 4 | Spring Boot Forum
S
Sailee Naik Posted on 30/03/2020

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'loginController': Unsatisfied dependency expressed through field 'userRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract com.test.beans.User com.test.repository.UserRepository.searchByName(java.lang.String)!

 

I am getting error and not sure whats wrong with any of the code... i have cross verified with code i downloaded from website 

 

kindly help me understand whats wrong wit my program ?


Y
Yogesh Chawla Replied on 30/03/2020

Something wrong is written in User Respository class. Have you written @Query annotation on top of 'searchByName' method to search out for products in the database.

Just paste the User Repository Class here. We can also check and confirm if something wrong is there.

 

And have you created Product and User tables in database. Refer 'resources' folder in the code to get all queries.

If the product info exist in the table then this method will search and display the same products on UI.


S
Sailee Naik Replied on 30/03/2020

Here is my UserRepository class , i did include Query annotation

package com.test.repository;

import com.test.beans.User;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

@Repository
public interface UserRepository extends CrudRepository<User,Integer> {

@Query("select u from User u where u.username = :name")
public User searchByName(@Param("name")String username);

}

I am not using MySQL , i am using H2 database ...Product and User tables are created in DB


S
Sailee Naik Replied on 30/03/2020

Never mind yogesh.... its very silly mistake on my end ..in the User bean the attribute is defined as "userName" and i was using "username" (without camel case) in Query

I spent 2 hours cracking my head....but turned out to be mole hill

THanks for quick response