You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring项目启动报UnsatisfiedDependencyException的排查与解决

解决Spring Boot UnsatisfiedDependencyException Bean创建失败问题

问题场景

开发包含StudentConfig、Student实体类、StudentController、StudentService、StudentRepository的基础Spring Boot项目时,启动抛出UnsatisfiedDependencyException,无法完成相关Bean的创建。

错误根源

排查后确认,问题出在StudentRepository的@Query注解语句中:语句里使用了大写的EMAIL,但Student实体类中对应的属性是小写的email,Hibernate无法解析这个不匹配的属性名,最终导致Bean依赖注入失败。

修复方案

修改StudentRepository中@Query语句内的属性名,使其与实体类属性名保持一致:

错误示例

@Query("SELECT s FROM Student s WHERE s.EMAIL = ?1")
Optional<Student> findByEmail(String email);

正确示例

@Query("SELECT s FROM Student s WHERE s.email = ?1")
Optional<Student> findByEmail(String email);

修改后重启项目,即可正常创建Bean并启动服务。

内容的提问来源于stack exchange,提问作者program

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.21 15:34:43