天天看点

学习Spring data 中org.springframework.beans.factory.BeanCreationException: Could not autowire field:错误

在学习spring data的过程中,发现报错 Repository bean 加载不到IOC容器中 ,发现配置文件正确 ,包也扫描了,注解也加了还是报错。最后发现:

@Modifying
	@Query("update person p set p.email= :email where p.id = :id")
	void updatePersonEmail(@Param("id")Integer id ,@Param("email")String email) ;
           

是sql语句写错了,应将person改为Person

@Modifying
	@Query("update Person p set p.email= :email where p.id = :id")
	void updatePersonEmail(@Param("id")Integer id ,@Param("email")String email) ;
           

运行通过!我们发现SQL语句写错也会出现加载不到IOC容器的问题,所以以后写代码一定要小心啊!

继续阅读