spring boot 2.x和hibernate整合 异常org.springframework.beans.factory.UnsatisfiedDependencyException

我在整合spring boot 2.x和hibernate时,启动报错,错误如下:
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘menuServiceImpl’: Unsatisfied dependency expressed through field ‘menuDao’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘menuDao’: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract int com.sxzq.glq.user.modules.user.dao.MenuDao.updateMenuByCode(java.lang.String,java.lang.String)!
错误原因:
  我的数据库表名和对应的实体类不一致,而我是第一次使用hibernate,对其不是很了解,在dao层,sql语句中将操作的对象写成了数据库表名,导致这个错误
  错误代码:
  @Query(“update menu set name = :name where code = :code”)
  public int updateMenuByCode(@Param(“name”) String name,@Param(“code”) String code);
  我写的操作对象为menu,是我数据库的表名,我对应的实体类是MenuEntity,所以报错了,修改后正确的代码为:
  @Query(“update MenuEntity set name = :name where code = :code”)
  public int updateMenuByCode(@Param(“name”) String name,@Param(“code”) String code);

猜你喜欢

转载自blog.csdn.net/wshicainiao/article/details/84661026
今日推荐