Springboot异常:: Error creating bean w...

时间:2024-12-20 07:52:43

今天本菜鸟编写程序时,遇到了一个异常.

: Error creating bean with name 'userController': Unsatisfied dependency expressed through field 'userService'; nested exception is : Error creating bean with name 'userServiceImpl': Unsatisfied dependency expressed through field 'userDao'; nested exception is : Error creating bean with name 'userDao': Invocation of init method failed; nested exception is : Validation failed for query for method public abstract int ()!
Caused by: : Error creating bean with name 'userServiceImpl': Unsatisfied dependency expressed through field 'userDao'; nested exception is : Error creating bean with name 'userDao': Invocation of init method failed; nested exception is : Validation failed for query for method public abstract int ()!
at $(:596) ~[spring-beans-5.1.:5.1.]
at (:90) ~[spring-beans-5.1.:5.1.]
at (:374) ~[spring-beans-5.1.:5.1.]
at (:1411) ~[spring-beans-5.1.:5.1.]
at (:592) ~[spring-beans-5.1.:5.1.]
at (:515) ~[spring-beans-5.1.:5.1.]
at $doGetBean$0(:320) ~[spring-beans-5.1.:5.1.]
at (:222) ~[spring-beans-5.1.:5.1.]
at (:318) ~[spring-beans-5.1.:5.1.]
at (:199) ~[spring-beans-5.1.:5.1.]
at (:277) ~[spring-beans-5.1.:5.1.]
at (:1247) ~[spring-beans-5.1.:5.1.]
at (:1167) ~[spring-beans-5.1.:5.1.]
at $(:593) ~[spring-beans-5.1.:5.1.]
... 19 common frames omitted
Caused by: : Error creating bean with name 'userDao': Invocation of init method failed; nested exception is : Validation failed for query for method public abstract int ()!
Caused by: : Validation failed for query for method public abstract int ()!
at (:93) ~[spring-data-jpa-2.1.:2.1.]
Caused by: : : tb_user is not mapped [select count(*) from tb_user u where =?
Caused by: : tb_user is not mapped [select count(*) from tb_user u where =?1]
at (:79) ~[hibernate-core-5.3.:5.3.]
at (:103) ~[hibernate-core-5.3.:5.3.]
... 79 common frames omitted
Caused by: : tb_user is not mapped
at (:169) ~[hibernate-core-5.3.:5.3.]
at (:91) ~[hibernate-core-5.3.:5.3.]

Caused by: : : tb_user is not mapped [select count(*) from tb_user u where =?
at (:138) ~[hibernate-core-5.3.:5.3.]

Caused by: : tb_user is not mapped [select count(*) from tb_user u where =?1]
at (:79) ~[hibernate-core-5.3.:5.3.]
Caused by: : tb_user is not mapped

异常太长了,中间的就删了,本着出现异常从后看起的思想,我们找到最后一条:

Caused by: : tb_user is not mapped

继续往上:

可以看出应该是这个sql语句出错了,没有映射,将tb_user改为User类,成功启动