springboot启动报错总结

SpringBoot启动时报错:

自己一些不懂的总结一下: 

Error creating bean with name 'certController': Unsatisfied dependency expressed through field 'certDao'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'certDao': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract com.dianju.modules.cert.models.Cert com.dianju.modules.cert.models.CertDao.finCertByIdentNo(java.lang.String)!

翻译得到TT

创建名称为“ certController”的bean时出错:通过字段“ certDao”表示的不满意的依赖关系; 嵌套的异常是org.springframework.beans.factory.BeanCreationException:创建名称为'certDao'的bean时出错:调用init方法失败; 嵌套异常为java.lang.IllegalArgumentException:方法公共抽象com.dianju.modules.cert.models.Cert com.dianju.modules.cert.models.CertDao.finCertByIdentNo(java.lang.String)的查询验证失败!

后端使用的是hibernate

出错代码:

@Query(value="select c from Cert c where c.identNo=?1 and (c.cert_status =0 or c.cert_status =4)")
Cert finCertByIdentNo(String identNo);

实体类:

// 证件号码
@Column(name = "ident_no", length = 50, nullable = false)
private String identNo;
// 证书状态
@Column(name = "cert_status", length = 2, nullable = false)
private int certStatus;

主要原因是SQL语句中的使用的是实体类,不是数据库库中的字段,所以会报错,可以将SQL语句修改为数据库中的字段,在后面加上nativeQuery = true,使用原生SQL,或者是使用实体类中的名称。

扫描二维码关注公众号,回复: 9645702 查看本文章

开始前我的修改是直接加上nativeQuery = true,虽然是能运行,但是这个不严谨,后面可能还是会出错,还是直接改为使用实体类中的名称最好。

修改如下:

@Query(value="select c from Cert c where c.identNo=?1 and (c.certStatus =0 or c.certStatus =4)")

nativeQuery = true: 主要是使用原生sql

所谓本地查询,就是使用原生的sql语句(根据数据库的不同,在sql的语法或结构方面可能有所区别)进行查询数据库的操作。

原文:https://www.cnblogs.com/zj0208/p/6008627.html

参考:https://blog.csdn.net/myme95/article/details/84143341

发布了15 篇原创文章 · 获赞 2 · 访问量 4227

猜你喜欢

转载自blog.csdn.net/weixin_41858337/article/details/102495744